
//
//  GetCarViewController.m
//  ICrEAM
//
//  Created by mac on 16/10/24.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "GetCarViewController.h"
#import "ICMProgressHeaderView.h"
#import "ICMHeaderView.h"
#import "AppDelegate.h"
#import "ICMBottomBarView.h"
#import "GetCarPreviewControllerViewController.h"
#import "ICMRepairEventAndPartSearchViewController.h"
#import "ICMCustomerInfoView.h"
#import "MonitorViewController.h"
#import "ICMCustomerInfoModel.h"
#import "ICMCustomerAndCarViewController.h"
#import "ICMSaveReceptionVehicleOrderApi.h"
#import "ICMPictureModel.h"
#import "AFNetworking.h"
#import "SYQRCodeViewController.h"
#import "PopoverSelectionViewController.h"
#import "RepairTypeSelectView.h"
#import "ICMCarModel.h"
#import "ICMPersonerModel.h"
#import "ICrEAMUser.h"
#import "ICMCreateFileView.h"
#import "ICMPropertyManager.h"
#import "RelectiveAppointMentModel.h"
#import "ICMAppointmentPreviewViewController.h"
#import "MoreCarInfoView.h"
#import "InformationComparisonViewController.h"
#import "PlanteNumberChangeViewController.h"
#import "PlateNumberChangeAlterViewController.h"
#import "TransferViewController.h"
@interface GetCarViewController ()<UIScrollViewDelegate,ICMHeaderViewDelegate,ICMAppearanceCheckViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,ICMBottomBarViewDelegate,ICMMaintenanceAndPartsViewDelegate,ICMGetCarBasicInfoViewDelegate,ICMProgressHeaderViewDelegate,AVAudioRecorderDelegate,RepairTypeDelegate,ICMCustomerInfoViewDelegate,MoreCarInfoViewDelegate,ICMCreateFileViewDelegate,ICMTitleTextFeildViewDelegate>{
    NSString *_receptionDate;
    NSString *_defaultLisence;
    NSString *_defaultVin;
    NSString *car_Num;
    NSString *onwerNo;
    NSInteger textFtype;
    CustomRecordModel *saveModel;
    NSString *VEHICLE_LIFE_STATUS;
    NSString *LABOUR_PRICE;//非保有客户调取零件字段
    NSUInteger changeCarNumberType;
    NSString *changeCarNumber;
    
}

@property (nonatomic, strong) ICMHeaderView *headerView;//头部view

@property (nonatomic, strong) UIScrollView *bigScrollView;//srcollview

@property (nonatomic, assign) BOOL imageIsAppearance;//是否是外部图片

@property (nonatomic, strong) ICMProgressHeaderView *progressHeaderView;//单据进度view

@property (nonatomic, strong) ICMBottomBarView *bottomBarView;//底部bar

@property (nonatomic, strong) ICMCustomerInfoView *qrCodeInfoView;//左滑监控信息view

@property (nonatomic, strong) NSString *qrString;//vin

@property (nonatomic, strong) UIView *blankView;//空白view

@property (nonatomic, strong) RepairTypeSelectView *repairTypeSelectView;//维修类型view

@property (nonatomic, strong) ICMCarModel *carModel;//车辆model
@property (nonatomic, strong) ICMPersonerModel *personerModel;//车主model

@property (nonatomic, strong) ICMCreateFileView *CreateFileView;//快速建档view

//请求过来的数据
@property (nonatomic, strong) NSMutableArray *packages;

@property (nonatomic, strong) NSString *showMessage;//msg

@property(nonatomic,strong) ICMCustomerInfoModel *cusomerInfo;//顾客信息model



//录音
@property (nonatomic, strong) AVAudioRecorder *audioRecorder;
@property (nonatomic, strong) AVAudioPlayer *audioPlayer;
@property (nonatomic, assign) BOOL couldRecord;
@property (nonatomic, assign) BOOL haveRecord;
//录音地址
@property (nonatomic, strong) NSString *file;

//顶部进度条字典
@property (nonatomic, strong) NSMutableDictionary *progressDic;


@property (nonatomic, assign) BOOL isPayForType;//索赔类型

@property (nonatomic, assign) BOOL isDisAppear;//是否消失

@property (nonatomic, assign) BOOL isPrinted;//返回时判断是否打印过

//多车辆信息view
@property (nonatomic, strong) MoreCarInfoView *moreCarInfoView;

//活动页显示信息用view
@property (nonatomic, strong) UIView *actMsgBgView2;
@property (nonatomic, strong) UILabel *actMsgLabel2;
@property (nonatomic, strong) PlanteNumberChangeViewController *plantCtr;
@property (nonatomic, strong) PlateNumberChangeAlterViewController *plantAlterCtr;

@property (nonatomic, assign) BOOL isContingency;//接车单入口进入的关联判断
@property (nonatomic, assign) BOOL customerViewHide;
@property (nonatomic, weak) NSString *AppointmentRelevanceState;//创建预约单入口关联判断

@end

@implementation GetCarViewController
-(NSMutableArray *)imageModels{
    if (!_imageModels) {
        _imageModels = [NSMutableArray array];
    }
    return _imageModels;
}

- (ICMCustomerInfoView *)qrCodeInfoView{
    if (!_qrCodeInfoView) {
        _qrCodeInfoView = [[[NSBundle mainBundle] loadNibNamed:@"ICMCustomerInfoView" owner:nil options:nil] firstObject];
    }
    return _qrCodeInfoView;
}

- (ICMCustomerInfoModel *)cusomerInfo{
    if (!_cusomerInfo) {
        _cusomerInfo = [[ICMCustomerInfoModel alloc]init];
    }
    return _cusomerInfo;
}

- (UIView *)blankView{
    if (!_blankView) {
        _blankView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
        _blankView.backgroundColor = [UIColor colorWithHex:BorderColor_Gray_Hex andAlpha:0.8];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideAllView)];
        [_blankView addGestureRecognizer:tap];
    }
    return _blankView;
}

- (RepairTypeSelectView *)repairTypeSelectView {
    if (!_repairTypeSelectView) {
        _repairTypeSelectView = [RepairTypeSelectView creatSelectViewWithFrame:CGRectMake(ActualWidth(207), ActualHeight(80), ActualWidth(610), ActualHeight(590)) andSelectedData:self.selectedRepairTypes andGetCar:YES];
        _repairTypeSelectView.delegate = self;
    }
    return _repairTypeSelectView;
}

- (NSMutableArray *)selectedRepairTypes {
    if (!_selectedRepairTypes) {
        _selectedRepairTypes = [NSMutableArray array];
    }
    return _selectedRepairTypes;
}

- (void)addProgressHeaderView{
    [self.progressHeaderView removeFromSuperview];
    self.progressHeaderView = [ICMProgressHeaderView createProgressHeaderViewWithStateDic:self.progressDic andFrame:CGRectMake(0, 40, ScreenWidth, 66)];
    self.progressHeaderView.delegate = self;
    [self.view  insertSubview:self.progressHeaderView belowSubview:self.suspendView];
}

-(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    self.audioRecorder=nil;
    [self.audioRecorder stop];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.isSave = NO;
    self.navigationItem.title = @"接车";
    self.automaticallyAdjustsScrollViewInsets = NO;
    //录音设置
    [self setAudioAndPlayer];
    self.haveRecord = NO;
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.headerView = [ICMHeaderView createHeaderViewWithFrame:CGRectMake(0, 0, ScreenWidth, 40) andTitles:[ICrEAMTool isVW]?@[@"基本信息",@"外部检查",@"保养套餐",@"活动选择",@"项目和零件"]:@[@"基本信息",@"外部检查",@"活动选择",@"项目和零件"] andType:@"0"];
    
    self.headerView.delegate = self;
    [self.view addSubview:self.headerView];
    
    self.progressDic = [@{@"1":@""} mutableCopy];
    [self addProgressHeaderView];
    
    ICMBottomBarView *bottomBarView = [ICMBottomBarView createBottomBarViewWithTitles:@[@"录 音",@"预 览",@"保 存",@"提 交",@"打印"] normalImages:@[[UIImage imageNamed:@"btn_record"],[UIImage imageNamed:@"btn_preview"],[UIImage imageNamed:@"btn_save"],[UIImage imageNamed:@"btn_synchronize"],[UIImage imageNamed:@"bottom_btn_print"]] seletedImages:nil andFrame:CGRectMake(0, ScreenHeight-70-NavBarHeight-StatusHeight, ScreenWidth, 70)];
    bottomBarView.delegate = self;
    self.bottomBarView = bottomBarView;
    [self.view addSubview:bottomBarView];
    [self setupBigScrollView];
    
    
    if (self.isEditType) {
        [self setUpAppICMAppearanceCheckView];
    }
    if (self.isEditType || self.isAppointmentType) {
        self.basicInfoView.vinNumberView.userInteractionEnabled = YES;
//        [self licenseDidEndEdit:self.basicInfoView.vinNumberView type:@"0"];
    }
    
    self.carePackageView.isEditType = self.isEditType;
    self.selecteActivityView.isEditType = self.isEditType;
    self.selecteActivityView.isAppointmentType = self.isAppointmentType;
    self.selecteActivityView.otherInfoModel = self.otherInfoModel;
    self.selecteActivityView.vinNumberView = self.basicInfoView.vinNumberView;
    self.partsView.carTypeView = self.basicInfoView.carTypeView;
    self.carePackageView.carTypeView = self.basicInfoView.carTypeView;
    
    if (self.isIn) {
        //已进站
        for (int i = 0; i < bottomBarView.bottomButtons.count; i++) {
            if (i != 1) {
                UIButton *button = bottomBarView.bottomButtons[i];
                button.alpha = 0.5;
                button.enabled = NO;
            }
        }
    }
    else
    {
        //未进站
        //新建及编辑接车单时 只有 录音、保存按钮可点击
        UIButton *button1 = bottomBarView.bottomButtons[1];
        button1.alpha = 0.5;
        button1.enabled = NO;
        
        UIButton *button3 = bottomBarView.bottomButtons[3];
        button3.alpha = 0.5;
        button3.enabled = NO;
        
        UIButton *button4 = bottomBarView.bottomButtons[4];
        button4.alpha = 0.5;
        button4.enabled = NO;
    }
    
    
    //头部跳转用赋值
    super.super_VIN = self.basicInfoModel.VIN;
    super.super_owner_no = self.basicInfoModel.OWNER_NO;
    
    self.isPrinted = YES;
    
    if(_isGetCar == YES){
        _recordModel = self.customerModel;
        
        
    }

    
    
    
    
}
- (void)OWNER_NO_notification:(NSNotification *)notification{
    NSString *OWNER_NO = [[notification userInfo] objectForKey:@"OWNER_NO"];
    NSString *OWNER_MOBILE = [[notification userInfo] objectForKey:@"OWNER_MOBILE"];
    NSString *OWNER_NAME = [[notification userInfo] objectForKey:@"OWNER_NAME"];
    self.basicInfoView.ownerNameView.contentText = OWNER_NAME;
    self.basicInfoView.ownerPhoneNumberView.contentText = OWNER_MOBILE;
    self.basicInfoModel.OWNER_NO = OWNER_NO;
    self.basicInfoModel.OWNER_NAME = OWNER_NAME;
    self.basicInfoModel.OWNER_MOBILE = OWNER_MOBILE;
    self.basicInfoModel.MOBILE = OWNER_MOBILE;
    [self saveGetCarOrder];
}
- (void)echoNotification:(NSNotification *)notification{
    [self saveGetCarOrder];
}
#pragma mark    返回按钮
- (void)backButtonClick{
    [self backButtonOrHomePageButtonAction:YES];
}

#pragma mark    返回首页
- (void)didbackHomePage{
    [self backButtonOrHomePageButtonAction:NO];
}

#pragma mark    返回按钮，判断是否有没有保存的信息
- (void)backButtonOrHomePageButtonAction:(BOOL)isBackButton{
    if (!self.isPrinted) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"接车单未打印，确认返回？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles: @"确定", nil];
        [alert show];
    } else {
        if (self.isEditType || self.isAppointmentType || self.isSave) {
            isBackButton?[self.navigationController popViewControllerAnimated:YES]:[self.navigationController popToRootViewControllerAnimated:YES];
            return;
        }
        
        BOOL haveText = NO;
        if ([ICMPropertyManager isHaveTextInTextField:self.basicInfoView]) {
            haveText = YES;
        }
        if (self.appearanceCheckView.appearancePoints.count || self.appearanceCheckView.innerPoints.count || self.appearanceCheckView.appearanceImages.count || self.appearanceCheckView.innerImages.count ||[ICMPropertyManager isHaveTextInTextField:self.appearanceCheckView]) {
            haveText = YES;
        }
        if (self.carePackageView.careSelectedItems.count || self.carePackageView.careSelectedItemIndexs.count || self.carePackageView.isHave_Other || self.carePackageView.isHave_Wheel || self.carePackageView.isHave_Wiper || self.carePackageView.isHave_Brake_block || self.carePackageView.isHave_Lubrication || self.carePackageView.isHave_AIR_SYSTEM_MAINTENANCE || self.carePackageView.isHave_FUEL_SYSTEM_MAINTENANCE || self.carePackageView.isHave_AIR_CONDITION_MAINTENANCE || !StrIsZero_gdm(self.carePackageView.Other_REMARK) || !StrIsZero_gdm(self.carePackageView.WHEEL_REMARK) || !StrIsZero_gdm(self.carePackageView.BRAKE_BLOCK_REMARK)) {
            haveText = YES;
        }
        if (self.selecteActivityView.selectedActivitys.count) {
            haveText = YES;
        }
        if (self.partsView.repairEventArray.count || self.partsView.repairPartsArray.count) {
            haveText = YES;
        }
        if (![self.partsView.partsRatioView.contentText isEqualToString:@"1.00"]||![self.partsView.workingRatioView.contentText isEqualToString:@"1.00"]||![self.partsView.finishTimeView.contentText isEqualToString:@""]) {
            haveText = YES;
        }
        if (haveText){
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"是否放弃当前数据？" delegate:self cancelButtonTitle:@"否" otherButtonTitles:@"是", nil];
            alert.tag = 2233;
            [alert show];
        }else{
            isBackButton?[self.navigationController popViewControllerAnimated:YES]:[self.navigationController popToRootViewControllerAnimated:YES];
        }
    }
}

//- (void)payTypesWrong{
//    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"维修类型索赔类和非索赔类不能同时选择!" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
//    [alert show];
//}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(presentVC:) name:@"popoverSelectionView" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didSelectRepairType:) name:@"RepairTypeChanged" object:nil];
    //    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(payTypesWrong) name:@"payTypesWrong" object:nil];
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getCarShowMessage:) name:@"GetCarShowMessage" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(createFileMsgNotifacation:) name:@"CreateFileMsgNotifacation" object:nil];
    self.isDisAppear = NO;
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(echoNotification:) name: @"saveOrder" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(OWNER_NO_notification:) name: @"OWNER_NO" object:nil];

}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.isDisAppear = YES;
    //    [self.blankView removeFromSuperview];
    //    [self.CreateFileView removeFromSuperview];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark    设置整个滚动页面
- (void)setupBigScrollView{
    if(self.bigScrollView)
    {
        [self.bigScrollView removeFromSuperview];
        self.bigScrollView = nil;
    }
    self.bigScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake( 0, self.progressHeaderView.bottomEdge, ScreenWidth, ScreenHeight-240)];
    //
    self.basicInfoView = [ICMGetCarBasicInfoView createICMGetCarBasicInfoViewWithFrame:CGRectMake(0, 0, ScreenWidth, CGRectGetHeight(self.bigScrollView.frame))];
    self.basicInfoView.delegate = self;
    
    self.appearanceCheckView = [ICMAppearanceCheckView createAppearanceCheckViewWithFrame:CGRectMake(ScreenWidth, 0, ScreenWidth, CGRectGetHeight(self.bigScrollView.frame)) andIsfromPreview:NO];
    [self setUpAppICMAppearanceCheckView];
    self.appearanceCheckView.delegate = self;
    if ([ICrEAMTool isVW]) {
        self.carePackageView = [ICMCarePackageView createCarePackageViewWithFrame:CGRectMake(2*ScreenWidth, 0, ScreenWidth, CGRectGetHeight(self.bigScrollView.frame))];
        self.carePackageView.getcarCtr=self;
    }
    self.selecteActivityView = [ICMSelecteActivityView createSelecteActivityViewWithFrame:CGRectMake(3*ScreenWidth, 0, ScreenWidth, CGRectGetHeight(self.bigScrollView.frame))];
    self.partsView = [ICMMaintenanceAndPartsView createICMMaintenanceAndPartsViewWithFrame:CGRectMake(4*ScreenWidth, 0, ScreenWidth, CGRectGetHeight(self.bigScrollView.frame))];
    self.partsView.repairTypes = self.selectedRepairTypes;
    self.partsView.delegate = self;

    self.partsView.modelCode = self.basicInfoModel.MODEL_CODE;
    
    [self.bigScrollView addSubview:self.basicInfoView];
    [self.bigScrollView addSubview:self.appearanceCheckView];
    if ([ICrEAMTool isVW]) {
        [self.bigScrollView addSubview:self.carePackageView];
    }else{
        [self.selecteActivityView changeXToOtherX:2*ScreenWidth];
        [self.partsView changeXToOtherX:3*ScreenWidth];
    }
    [self.bigScrollView addSubview:self.selecteActivityView];
    [self.bigScrollView addSubview:self.partsView];
    //
    self.bigScrollView.pagingEnabled = YES;
    self.bigScrollView.delegate = self;
    self.bigScrollView.showsHorizontalScrollIndicator = NO;
    self.bigScrollView.contentSize = CGSizeMake(ScreenWidth*([ICrEAMTool isVW]?5:4), ScreenHeight-240);
    [self.view addSubview:self.bigScrollView];
    
    if (self.isEditType || self.isAppointmentType) {
        [self setupAllDataViewsWithModels];
    }
}
#pragma mark    设置快速建档界面
- (void)setupCreateFileView{
    self.CreateFileView = [ICMCreateFileView creatICMCreateFileViewWithFrame:CGRectMake((ScreenWidth-ActualWidth(940))/2, (ScreenHeight-ActualHeight(490))/2, ActualWidth(940), ActualHeight(490)) withType:2];
    if (self.qrString) {
        self.CreateFileView.vinNumberView.contentText = self.qrString;
    }
    self.CreateFileView.type = 2;
        if(_isEditType){
        
        self.CreateFileView.customModel = _editModel;
    
    }else{
        if(!saveModel){
            self.CreateFileView.customModel = [self getInterfaceData];
        }else{
            self.CreateFileView.customModel = saveModel;
            
        }

    }
    
    //单独判断
    if(_isGetCar == YES){
        _recordModel = self.customerModel;
        _recordModel.SALES_DATE = [ICrEAMTool getDateWithTimeInterval:self.customerModel.SALES_DATE];
        self.CreateFileView.customModel = _recordModel;
    }
    
    if(!IsStrEmpty(self.qrString)){
        self.CreateFileView.vinNumberView.contentText = self.qrString;
    }
    
    self.CreateFileView.delegate = self;
    self.CreateFileView.hidden = NO;
    self.blankView.hidden = NO;
    [self.view addSubview:self.blankView];
    [self.view addSubview:self.CreateFileView];
}
//从界面上获取值后赋与快速建档用模型
-(CustomRecordModel*)getInterfaceData{
    if(!_recordModel){
        
        _recordModel = [[CustomRecordModel alloc]init];
    }else{
        _record_Model = [[CustomRecordModel alloc]init];
    }
    if(textFtype == 0){
        _record_Model = _recordModel;
        
        return _record_Model;
    }
    
    if(!self.basicInfoModel){
    
    }
    
    _recordModel.VIN = self.basicInfoView.vinNumberView.contentText;
    _recordModel.CUS_RECORD_ID = self.basicInfoModel.CUS_RECORD_ID;
    _recordModel.OWNER_NAME = self.basicInfoView.ownerNameView.contentText;
    _recordModel.OWNER_PROPERTY = _personerModel.ownerType;
    _recordModel.SALES_DATE = self.basicInfoView.invoiceDateView.contentText;
    _recordModel.LICENSE = [self getTextFieldAreaAndPlate];
    _recordModel.GENDER = _personerModel.gender;
    _recordModel.ITEM_ID = @"";
    _recordModel.CONTACTOR_NAME = self.basicInfoView.customerNameView.contentText;
    _recordModel.CONTACTOR_MOBILE = self.basicInfoView.customerPhoneNumberView.contentText;
    _recordModel.CITY = _personerModel.city;
    _recordModel.PROVINCE = _personerModel.province;
    _recordModel.DISTRICT = _personerModel.district;
    _recordModel.MOBILE = self.basicInfoView.ownerPhoneNumberView.contentText;
    _recordModel.MILEAGE = self.basicInfoView.currentMileageView.contentText;
    _recordModel.VEHICLE_LIFE_STATUS = self.basicInfoModel.VEHICLE_LIFE_STATUS;
    _recordModel.OWNER_NO = self.basicInfoModel.OWNER_NO;
    _recordModel.BUSINESS_KIND = saveModel.BUSINESS_KIND;
    
    _recordModel.MODEL_CODE = _carModel.carType;
    _recordModel.MODEL_NAME = _carModel.carTypeName;
    
    _recordModel.SERIES_CODE = _carModel.SERIES_CODE;
    _recordModel.SERIES_NAME = _carModel.SERIES_NAME;

    return _recordModel;
}

#pragma mark    快速建档保存
- (void)clickSave:(CustomRecordModel *)model{
    self.basicInfoView.vinNumberView.contentText = model.VIN;
    
    self.recordModel = model;
    saveModel = model;

    NSString *area = @"";
    NSString *plant = @"";
    
    if (model.LICENSE.length>2) {
        area = [model.LICENSE substringWithRange:NSMakeRange(0, 1)];
        plant = [model.LICENSE substringWithRange:NSMakeRange(1, model.LICENSE.length-1)];
        unsigned char mCode;
        sscanf([area UTF8String], "%c", &mCode);
        if (mCode <= 'Z' && mCode >= 'A') {
            area = [model.LICENSE substringWithRange:NSMakeRange(0, 2)];
            plant = [model.LICENSE substringWithRange:NSMakeRange(2, model.LICENSE.length-2)];
        }
    }
    self.basicInfoView.ownerNameView.contentText = model.OWNER_NAME;
    self.basicInfoView.ownerTypeView.contentText = [ICrEAMTool getCodeModelForCode:model.OWNER_PROPERTY].desc;;
    self.basicInfoView.selectAreaView.contentText = area;
    self.basicInfoView.plateNumberView.contentText = plant;
    
    self.basicInfoView.ownerNameView.contentText = model.OWNER_NAME;
    self.basicInfoView.invoiceDateView.contentText = model.SALES_DATE;
    
    self.basicInfoView.carTypeView.contentText = [NSString stringWithFormat:@"%@|%@",model.MODEL_CODE,model.MODEL_NAME];
    self.basicInfoView.carTypeView.noStr = model.MODEL_CODE;
    self.basicInfoModel.MODEL_NAME = model.MODEL_NAME;
    self.basicInfoModel.VEHICLE_LIFE_STATUS = model.VEHICLE_LIFE_STATUS;
    self.basicInfoView.ownerPhoneNumberView.contentText = model.CONTACTOR_MOBILE;
    self.basicInfoView.ownerTypeView.contentText = [ICrEAMTool getCodeModelForCode:model.OWNER_PROPERTY].desc;
    self.basicInfoModel.BUSINESS_KIND = model.BUSINESS_KIND;
    self.carModel.carNature = model.BUSINESS_KIND;
    self.basicInfoView.customerNameView.contentText=model.CONTACTOR_NAME;
    self.basicInfoView.customerPhoneNumberView.contentText=model.CONTACTOR_MOBILE;
    //    [self removeBroadsideView];
    
    self.basicInfoModel.MODEL_CODE = model.MODEL_CODE;
    self.carModel.carType = model.MODEL_CODE;
    
    
    [self hideAllView];
}

#pragma mark 快速建档回调查询
-(void)syncCustomInfoWithText:(NSString *)text isVin:(BOOL)isVin{
    ICMRequestManager *manager = [[ICMRequestManager alloc]init];
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    if (isVin) {
        if (text && [ICrEAMTool isVinText:text]){
            [parameters setObject:@"" forKey:@"LICENSE"];
            [parameters setObject:text forKey:@"VIN"];
        }else{
            [self.view showString:@"VIN码输入有误！" forSeconds:1.5];
            return;
        }
    }else{
        [parameters setObject:text forKey:@"LICENSE"];
        [parameters setObject:@"" forKey:@"VIN"];
    }
    
    [manager startGetRequestWithURL:QueryOwnerByVinLicense parameters:parameters inHudView:self.view andResultBlock:^(id data, NSString *failText) {
        if ([data[@"CODE"] integerValue] == 200) {
            if ([data[@"DATA_STATUS"] integerValue] == 0){
                return;
                
            }else{
                
                NSArray *carModelArray = data[@"TM_VEHICLE"];
                if (![carModelArray isKindOfClass:[NSArray class]]) {
                    return;
                }
                CustomRecordModel *customModel=[[CustomRecordModel alloc]init];
                if (carModelArray.count>0) {
                    ICMCarModel *carModel = [ICMCarModel yy_modelWithDictionary:data[@"TM_VEHICLE"][0]];
                    customModel.VEHICLE_LIFE_STATUS=carModel.VEHICLE_LIFE_STATUS;
                    customModel.VIN=carModel.vinNum;
                    customModel.LICENSE=carModel.carNum;
                    customModel.BRAND_CODE=carModel.brand;
                    customModel.BRAND_NAME=carModel.brandName;
                    customModel.SERIES_CODE=carModel.carKei;
                    customModel.SERIES_NAME=carModel.carKeiName;
                    customModel.MODEL_CODE=carModel.carType;
                    customModel.MODEL_NAME=carModel.carTypeName;
                    customModel.BUSINESS_KIND=carModel.carNature;
                    customModel.SALES_DATE= [ICrEAMTool getDateWithTimeInterval:carModel.SALES_DATE];
                    customModel.OWNER_NO=carModel.OWNER_NO;
                    customModel.MILEAGE=carModel.lastMillions;
                    
                    if ([carModel.VEHICLE_LIFE_STATUS isEqualToString:@"25271001"]) {
                        [self alertMessage:@"该车辆为售前车辆，不支持预约和接车流程！" withBlock:^{
                            [self.CreateFileView removeFromSuperview];
                            self.recordModel=nil;
                        }];
                        return;
                    }
                    
                    
                    self.CreateFileView.dateView.contentText=[ICrEAMTool getDateWithTimeInterval:carModel.SALES_DATE];
                    self.CreateFileView.natureView.contentText=[ICrEAMTool getCodeModelForCode:carModel.carNature].desc;
                     self.carModel=carModel;
                    if (![self.CreateFileView.selectAreaView.contentText isEqualToString:carModel.carNum]) {
//                        changeCarNumberType = 4;
//                        [self addPlantAlter:self.CreateFileView.selectAreaView.contentText];
                        [self carChangeAlertMessage:@"车牌发生变化，选择“是”使用新车牌，选“否”选择老车牌！" withSuccessBlock:^{

                               car_Num= self.CreateFileView.selectAreaView.contentText;
                          
                            customModel.LICENSE=self.CreateFileView.selectAreaView.contentText;
                           [self analysisData:data andmodel:customModel];
                           
                       } failBlock:^{
                           car_Num=@"";
                           
                            self.CreateFileView.selectAreaView.contentText=carModel.carNum;
                            [self analysisData:data andmodel:customModel];
                       }];
                    }else{
                          car_Num=@"";
                        [self analysisData:data andmodel:customModel];
                    }
                 
                   
                }
                
            }
        }
        
    }];
    
}
-(void)analysisData:(id)data andmodel:(CustomRecordModel*)customModel{
    NSArray *personerModelArray = data[@"TM_OWNER"];
    
    if (![personerModelArray isKindOfClass:[NSArray class]]){
        return;
    }
    if (personerModelArray.count>0) {
        ICMPersonerModel *personerModel = [ICMPersonerModel yy_modelWithDictionary:data[@"TM_OWNER"][0]];
        customModel.GENDER=personerModel.gender;
        customModel.PROVINCE=personerModel.province;
        customModel.CITY=personerModel.city;
        customModel.DISTRICT=personerModel.district;
        customModel.OWNER_NAME=personerModel.ownerName;
        customModel.CONTACTOR_NAME=personerModel.CONTACTOR_NAME;
        customModel.CONTACTOR_MOBILE=personerModel.CONTACTOR_MOBILE;
        customModel.MOBILE=personerModel.phoneNum;
        customModel.OWNER_PROPERTY=personerModel.ownerType;
   
        self.CreateFileView.nameView.contentText=personerModel.ownerName;
        self.CreateFileView.linkmanView.contentText=personerModel.CONTACTOR_NAME;
        self.CreateFileView.linkmanMobelView.contentText=personerModel.CONTACTOR_MOBILE;
        self.personerModel = personerModel;
        self.recordModel=customModel;
    }
    [self.view showString:@"该车辆信息已存在" forSeconds:1.5];
    
    dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0/*延迟执行时间*/ * NSEC_PER_SEC));
    
    dispatch_after(delayTime, dispatch_get_main_queue(), ^{
        [self.CreateFileView removeFromSuperview];
        
        [self getInfoWithLICENSE:@"" orVin:self.carModel.vinNum];
        
    });
}
-(void)textFiledShouldReturnWithText:(NSString *)text isVin:(BOOL)isVin{
    [self syncCustomInfoWithText:text isVin:isVin];
}
#pragma mark    点击扫描
- (void)clickQRCodeBtnWithType:(int)type{
    //    type : 0基本信息页面 1快速建档页面
    if (self.isEditType || self.isAppointmentType) {
        return;
    }
    
    NSString *ip = IP;
    
        OcrScanViewController *orc= [[OcrScanViewController alloc] init];
        orc.sframe=self.view.bounds;
    

        orc.SYQRCodeSuncessBlock = ^(OcrScanViewController *aqrvc,NSString *qrString){
        
        if ([ICrEAMTool isVinText:qrString]) {
            if (type == 1) {
                self.CreateFileView.vinNumberView.contentText = qrString;
                [self syncCustomInfoWithText:qrString isVin:YES];
               
            }else{
                self.basicInfoView.vinNumberView.contentText = qrString;
                [self syncCustomInfoWithText:qrString isVin:YES];
                [self getInfoWithLICENSE:@"" orVin:qrString];
                self.qrString = qrString;
            }
        }
        
        [aqrvc dismissViewControllerAnimated:YES completion:nil];
        
    };
    
    __weak typeof(self) weakself = self;
    orc.SYQRCodeCancleBlock = ^(OcrScanViewController *aqrvc){
        
        [weakself dismissViewControllerAnimated:YES completion:nil];
        if (type == 1) {
           [self setupCreateFileView];
        }
    };
    
        [self presentViewController:orc animated:YES completion:nil];
    
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    float offsetX = scrollView.contentOffset.x;
    //    [self.view endEditing:YES];
    self.headerView.selectedIndex = offsetX/ScreenWidth;
    [self didSelectedActivityOrCarePageAction:self.headerView.selectedIndex];
}

/*ICMHeaderViewDelegate*/
#pragma mark    点击选择界面按钮
- (void)headerViewDidSelectedButtonAtIndex:(NSInteger)index{
    [self.bigScrollView scrollRectToVisible:CGRectMake(ScreenWidth*index, 0, ScreenWidth, ScreenHeight-240) animated:YES];
    [self didSelectedActivityOrCarePageAction:index];
}
#pragma mark    点击活动或者套餐界面
- (void)didSelectedActivityOrCarePageAction:(NSInteger)index{
    [self.view endEditing:YES];
    //获取工时单价
       if(_isGetCar == YES){

    }else{
        
        if(index == 3){
            if(!self.carModel){
                
                [self getLABOUR_PRICE:self.recordModel.MODEL_CODE];
                
            }else{
                [self getLABOUR_PRICE:self.carModel.carType];
                
            }
        }
    }
    
    
    
    
    if (((index == 3 && [ICrEAMTool isVW])||(index == 2 && ![ICrEAMTool isVW]))) {
        self.haveShowActivity = YES;
        self.selecteActivityView.isPayForType = self.isPayForType;
        if (self.basicInfoView.haveChangeVIN) {
            self.basicInfoView.haveChangeVIN = NO;
            [self getActivity];
        }
        else
        {
            if(!self.selecteActivityView.activityModels || self.selecteActivityView.activityModels.count == 0)
            {
                if(self.actMsgBgView2)
                {
                    [self.actMsgBgView2 removeFromSuperview];
                }
                [self.selecteActivityView addSubview:self.actMsgBgView2];
                if(self.actMsgLabel2)
                {
                    [self.actMsgLabel2 removeFromSuperview];
                }
                [self.actMsgBgView2 addSubview:self.actMsgLabel2];
            }
        }
    }
    else
    {
        [self.actMsgBgView2 removeFromSuperview];
        [self.actMsgLabel2 removeFromSuperview];
        self.actMsgBgView2 = nil;
        self.actMsgLabel2 = nil;
    }
    if ([ICrEAMTool isVW]&&self.headerView.selectedIndex == 2) {
        if (self.basicInfoView.haveChangeCarModel) {
            self.basicInfoView.haveChangeCarModel = NO;
            [self getCarePackage];
        }
    }
   

}

#pragma mark 活动页显示信息用主view2
- (UIView *)actMsgBgView2
{
    if(!_actMsgBgView2)
    {
        _actMsgBgView2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, CGRectGetHeight(self.bigScrollView.frame))];
        _actMsgBgView2.backgroundColor = BackgroundColor_Gray;//[UIColor colorWithWhite:0.5 alpha:0.5];
    }
    return _actMsgBgView2;
}

#pragma mark 活动页显示信息用label
- (UILabel *)actMsgLabel2
{
    if(!_actMsgLabel2)
    {
        _actMsgLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(0, self.actMsgBgView2.frame.size.height/2-25, ScreenWidth, 50)];
        _actMsgLabel2.text = @"该车型暂无可参加的活动！";
        _actMsgLabel2.textAlignment = NSTextAlignmentCenter;
        //_actMsgLabel.backgroundColor = TitleColor_Dark;
        _actMsgLabel2.textColor = [UIColor blackColor];
        [_actMsgLabel2 sizeToFit];
        CGRect rect = _actMsgLabel2.frame;
        rect.origin.x = (ScreenWidth - rect.size.width)/2;
        rect.origin.y = (self.actMsgBgView2.frame.size.height - rect.size.height)/2;
        _actMsgLabel2.frame = rect;
    }
    return _actMsgLabel2;
}


/*ICMProgressHeaderViewDelegate*/
#pragma mark    当前单子进度按钮点击
- (void)progressHeaderViewDidSelectedIndex:(NSInteger)index{
    if(index == 0)
    {
        //预约预览
        if(self.basicInfoModel.BOOKING_ORDER_NO && ![self.basicInfoModel.BOOKING_ORDER_NO isEqualToString:@""])
        {
            NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
            [parameters setObject:self.basicInfoModel.BOOKING_ORDER_NO forKey:@"ORDER_ID"];
            ICMRequestManager *manager = [[ICMRequestManager alloc]init];
            [manager startGetRequestWithURL:BookingOrderDetils parameters:parameters inHudView:self.view andResultBlock:^(id data, NSString *failText) {
                
                if ([data[@"CODE"] integerValue] == 200) {
                    if (IsArr(data[@"TT_BOOKING_OEDER"])) {
                        ICMBasicInfoModel *tempBasicInfoModel = [ICMBasicInfoModel yy_modelWithDictionary:data[@"TT_BOOKING_OEDER"][0]];
                        ICMAppointmentOtherInfoModel *tempBasicOtherModel = [ICMAppointmentOtherInfoModel yy_modelWithDictionary:data[@"TT_BOOKING_OEDER"][0]];
                        ICMPartsTopModel *tempPartsTopModel = [ICMPartsTopModel yy_modelWithDictionary:data[@"TT_BOOKING_OEDER"][0]];
                        
                        ICMRepairMaintenancesModel *tempMaintenancesModel = [ICMRepairMaintenancesModel yy_modelWithDictionary:data];
                        [tempMaintenancesModel createRepairMaintenanceBookingModel];
                        
                        ICMRepairPartsArrayModel *tempPartsArrayModel = [ICMRepairPartsArrayModel yy_modelWithDictionary:data];
                        [tempPartsArrayModel createRepairPartsBookingModel];
                        
                        ICMActivityModel *tempActivityModel = [ICMActivityModel yy_modelWithDictionary:data];
                        [tempActivityModel createActivityItemBookingModel];
                        
                        ICMAppointmentPreviewViewController *PVC = [[ICMAppointmentPreviewViewController alloc]init];
                        PVC.basicInfoModel = tempBasicInfoModel;
                        PVC.basicOtherModel = tempBasicOtherModel;
                        PVC.partsTopModel = tempPartsTopModel;
                        PVC.maintenancesModel = tempMaintenancesModel;
                        PVC.partsArrayModel = tempPartsArrayModel;
                        PVC.activityModel = tempActivityModel;
                        [self.navigationController pushViewController:PVC animated:YES];
                    }
                    
                }
            }];
        }
    }
}

/*ICMAppearanceCheckViewDelegate*/
- (void)appearanceCheckViewAppearanceImageButtonAction{
    self.imageIsAppearance = YES;
    [self startToTakephotoFromCarmera];
}
- (void)appearanceCheckViewInnerImageButtonAction{
    self.imageIsAppearance = NO;
    [self startToTakephotoFromCarmera];
}

#pragma mark    拍照处理
- (void)startToTakephotoFromCarmera{
    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc]init];
    imagePickerController.delegate = self;
    imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
    imagePickerController.allowsEditing = NO;
    [self presentViewController:imagePickerController animated:YES completion:nil];
}

/*UIImagePickerControllerDelegate*/
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    [(self.imageIsAppearance?self.appearanceCheckView.appearanceImages:self.appearanceCheckView.innerImages) PACA_AddObject:image];
    if (self.imageIsAppearance) {
        [self.appearanceCheckView refreshAppearanceCollectionView];
    }else{
        [self.appearanceCheckView refreshInnerCollectionView];
    }
    [picker dismissViewControllerAnimated:YES completion:^{
        
    }];
}

/*ICMBottomBarViewDelegate*/
#pragma mark    底部功能按钮点击
- (void)bottomBarViewDidSelectIndex:(NSInteger)index{
    
    switch (index) {
        case 0:
        {
            
            if(self.haveRecord == NO){
                [self.view showString:@"录音开始" forSeconds:1.5];
                self.bottomBarView.recorderLabel.text = @"暂 停";
                [self clickRecordBtn];
                self.haveRecord = YES;
            }else{
                self.bottomBarView.recorderLabel.text = @"录 音";
                [self.view showString:@"录音暂停" forSeconds:1.5];
                [self clickPauseBtn];
                self.haveRecord = NO;
                
                
            }
            
        }
            break;
        case 1:
        {
            [self setupAllDataModels];
            
            GetCarPreviewControllerViewController *preview = [GetCarPreviewControllerViewController new];
            preview.isInner = YES;
            preview.basicInfoModel = self.basicInfoModel;
            
            preview.checkAppearanceTopModel = self.checkAppearanceTopModel;
            
            preview.checkAppearanceDownModel = self.checkAppearanceDownModel;
            
            preview.activityModel = self.activityModel;
            
            preview.carePackageModel = self.carePackageModel;
            
            preview.carePackageDownModel = self.carePackageDownModel;
            
            preview.partsTopModel = self.partsTopModel;
            
            preview.repairEventModel = self.repairEventModel;
            
            preview.repairPartsModel = self.repairPartsModel;
            
            [self.navigationController
             pushViewController:preview animated:YES];
            
            break;
        }
            
        case 2:{
            
            if (!self.haveShowActivity && self.selecteActivityView.selectedActivitys.count > 0) {
                UIAlertView *alter = [[UIAlertView alloc]initWithTitle:@"提示" message:@"该车辆可参加服务活动，请检查！" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
                [alter show];
                return;
            }
            [self uploadImagesAndThenSave];
            
            break;
        }
        case 3:{
            if (self.isSave&&self.getCarNumber) {
                self.isSubmit = YES;
                       [self submitISchecked:NO];
            }
            break;
        }
        case 4:{
            //打印
            if(self.getCarNumber && ![self.getCarNumber isEqualToString:@""])
            {
                [ICrEAMTool ipadPrintWithPrintType:GetCarPrintType printId:self.getCarNumber Controller:self  andEstimatePrice:nil];
                self.isPrinted = YES;
            }
            break;
        }
        default:
            break;
    }
}
#pragma mark    上传图片
- (void)uploadImagesAndThenSave{
    
    NSMutableDictionary *images = [NSMutableDictionary dictionary];
    [images setObject:[self.appearanceCheckView getImageWithType:0] forKey:@"0"];
    [images setObject:[self.appearanceCheckView getImageWithType:1] forKey:@"1"];
    [images setObject:self.appearanceCheckView.appearanceImages forKey:@"2"];
    [images setObject:self.appearanceCheckView.innerImages forKey:@"3"];
    [self UploadImages:images];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
        if([alertView.message isEqualToString:@"接车单未打印，确认返回？"]) {
            if (buttonIndex == 1) {
                [self.navigationController popViewControllerAnimated:YES];
            }
        }else if ([alertView.message isEqualToString:@"是否放弃当前数据？"]){
            if (buttonIndex == 1) {
                [self.navigationController popViewControllerAnimated:YES];
            }
        } else {
            if (buttonIndex == 1) {
                [self uploadImagesAndThenSave];
            }
        }

}

#pragma mark 保存接车单
- (void)saveReceptionCarOrder{
    NSString *BUSINESS_KIND = [NSString string];
    if(!saveModel){
    
        BUSINESS_KIND = _BUSINESS_KIND;
    }else{
        BUSINESS_KIND = saveModel.BUSINESS_KIND;
    }
    //保有
    if(IsStrEmpty(self.basicInfoModel.OWNER_NO)){
        self.isRetainer = NO;
    
    }else{
        self.isRetainer = YES;
    }
    
    
    
    if([BUSINESS_KIND isEqualToString:@"22011003"] && self.isRetainer == NO){
        if(self.isSave == NO){
            
            TransferViewController *transferVC = [[TransferViewController alloc]init];
            transferVC.view.centerX = self.blankView.frame.size.width/2;
            transferVC.view.centerY = self.blankView.frame.size.height/2;
            transferVC.ownerTextF.text = self.basicInfoView.ownerNameView.contentText;
            transferVC.ownerPhoneTextF.text = self.basicInfoView.ownerPhoneNumberView.contentText;
            [self addChildViewController:transferVC];
            
            [self.view addSubview:transferVC.blankView];
             [self.view addSubview:transferVC.view];
        
        }else{
            
            [self saveGetCarOrder];
        }
    
    }else{
        [self saveGetCarOrder];
    }
        
    

}

-(void)saveGetCarOrder{
    NSMutableDictionary *paraDic = [self getRecepetionCarOrderData];
    
    if(![self checkFormSaveData])
    {
        return;
    }
    
    NSString *url = [NSString stringWithFormat:@"/INFO_ICREAM_WEB/App/saveReceptionVehicleOrder"];
    [[[ICMRequestManager alloc]init]startPostRequestWithURL:url parameters:paraDic inHudView:self.view andResultBlock:^(id data, NSString *failText) {
        [self getCarePackage];
        if (!failText) {
            [self.view showString:@"保存成功" forSeconds:1.5f];
            self.isSave = YES;
            self.getCarNumber = data[@"RECEPTION_NO"];
            _receptionDate=data[@"RECEPTION_DATE"];
            [self.progressDic setObject:self.getCarNumber?:@"" forKey:@"1"];
            [self addProgressHeaderView];
            
            [ICrEAMTool savaOperationReceiptUserName:self.basicInfoModel.DELIVERER carSeries:!StrIsZero_gdm(self.basicInfoModel.SERIES_NAME)?self.basicInfoModel.SERIES_NAME:self.carModel.SERIES_NAME?:@"" licence:self.basicInfoModel.LICENSE status:@"接车单未提交" returnTime:self.partsTopModel.DELIVERY_DATE];
            //保存完 接车日期 今天
            //获取现在时间
            NSDate *currentDate = [NSDate date];
            NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
            [dateFormatter setDateFormat:@"YYYY-MM-dd"];
            NSString *dateString = [dateFormatter stringFromDate:currentDate];
            self.basicInfoModel.DELIVERY_DATE = dateString;
            
            //            [self.partsView setAllStateToInit];
            //保存成功 预约查询界面reload数据
            if (self.basicInfoModel.BOOKING_ORDER_NO) {
                [[NSNotificationCenter defaultCenter] postNotificationName:@"DidChangeAppointmentToGetCar" object:self userInfo:@{@"BOOKING_ORDER_NO":self.basicInfoModel.BOOKING_ORDER_NO}];
            }
            
            //接车单保存后，录音按钮变录 音，预览、提交按钮 可点击
            self.bottomBarView.recorderLabel.text = @"录 音";
            
            UIButton *button1 = self.bottomBarView.bottomButtons[1];
            button1.alpha = 1;
            button1.enabled = YES;
            
            UIButton *button3 = self.bottomBarView.bottomButtons[3];
            button3.alpha = 1;
            button3.enabled = YES;
            //保存成功后不能再保存
            //            [self.bottomBarView setButtonDisEnable:2];
            self.file = @"";
            
            self.repairEventModel = [ICMRepairMaintenancesModel yy_modelWithDictionary:data];
            [self.repairEventModel createRepairMaintenanceModel];
            self.repairPartsModel = [ICMRepairPartsArrayModel yy_modelWithDictionary:data];
            [self.repairPartsModel createRepairPartsModel];
            if (self.repairEventModel.TT_RECPTION_LABOUR.count) {
                [self.partsView setupPartsViewWithRepairMaintenancesModel:self.repairEventModel];
            }
            if (self.repairPartsModel.TT_RECPTION_PART.count) {
                [self.partsView setupPartsViewWithRepairPartsArrayModel:self.repairPartsModel];
            }
            [self.partsView refreshInEditType];
            
            //损伤图片
            self.imageModels = [NSMutableArray array];
            NSArray *images = data[@"TT_RECPTION_DAMANGE"];
            if (IsArr(images)) {
                for (NSDictionary *dic in images) {
                    ICMPictureModel *model = [ICMPictureModel yy_modelWithDictionary:dic];
                    [self.imageModels addObject:model];
                }
            }
            self.appearanceCheckView.picModels = self.imageModels;
            [self.appearanceCheckView.innerImages removeAllObjects];
            [self.appearanceCheckView.innerImages removeAllObjects];
            [self setUpAppICMAppearanceCheckView];
            
        }else{
            //保存失败
            [self.view showString:@"保存失败!" forSeconds:1.5f];
        }
    }];


}
#pragma mark    设置数据
- (void)setupAllDataModels{
    NSString *bookingOrderNo = self.basicInfoModel.BOOKING_ORDER_NO;
    NSString *series_name = self.basicInfoModel.SERIES_NAME;
    NSString *modelName = self.basicInfoModel.MODEL_NAME;
    NSString *deliveryDate = self.basicInfoModel.DELIVERY_DATE;
    //接车日期
    NSString *receptionDate = self.basicInfoModel.RECEPTION_DATE;
    NSString *CUS_RECORD_ID = self.basicInfoModel.CUS_RECORD_ID;
    self.basicInfoModel = [[ICMBasicInfoModel alloc]init];
    [self.basicInfoModel setupBasicInfoModelWithBasicInfoView:self.basicInfoView];
    self.basicInfoModel.VEHICLE_LIFE_STATUS = self.carModel.VEHICLE_LIFE_STATUS;
    self.basicInfoModel.BOOKING_ORDER_NO = bookingOrderNo;
    self.basicInfoModel.SERIES_NAME = series_name;
    self.basicInfoModel.MP3_FILE = self.file;
    self.basicInfoModel.MODEL_NAME = modelName;
    self.basicInfoModel.DELIVERY_DATE = deliveryDate;
    self.basicInfoModel.CUS_RECORD_ID = CUS_RECORD_ID;
    self.basicInfoModel.OWNER_NO = onwerNo;
    //接车日期
    //    if (IsStrEmpty(receptionDate)) {
    //        receptionDate=_receptionDate;
    //    }
    if(receptionDate && ![receptionDate isEqualToString:@""])
    {
        self.basicInfoModel.RECEPTION_DATE = receptionDate;
    }
    else
    {
        if(_receptionDate && ![_receptionDate isEqualToString:@""])
        {
            self.basicInfoModel.RECEPTION_DATE = _receptionDate;
        }
        else
        {
            self.basicInfoModel.RECEPTION_DATE = @"";
        }
    }
    
    self.checkAppearanceDownModel = [[ICMCheckAppearanceDownModel alloc]init];
    [self.checkAppearanceDownModel setupCheckAppearanceDownModelWithAppearanceCheckView:self.appearanceCheckView];
    
    if ([ICrEAMTool isVW]) {
        self.carePackageDownModel = [[ICMCarePackageDownModel alloc]init];
        [self.carePackageDownModel setupCarePackDownModelWithCarePackageView:self.carePackageView];
    }
    
    self.partsTopModel = [[ICMPartsTopModel alloc]init];
    [self.partsTopModel setupPartsTopModelWithPartsView:self.partsView];
    
    self.checkAppearanceTopModel = [[ICMCheckAppearanceTopModel alloc]init];
    [self.checkAppearanceTopModel setupAppearanceTopModelWithAppearanceCheckView:self.appearanceCheckView];
    
    self.carePackageModel = [[ICMCarePackageModel alloc]init];
    [self.carePackageModel setupCarePackageModelWithPackageView:self.carePackageView];
    
    self.activityModel = [[ICMActivityModel alloc]init];
    [self.activityModel setupActivityModelWithSelecteView:self.selecteActivityView];
    
    self.repairEventModel = [[ICMRepairMaintenancesModel alloc]init];
    [self.repairEventModel setupRepairMaintenancesModelWithPartsView:self.partsView];
    
    self.repairPartsModel = [[ICMRepairPartsArrayModel alloc]init];
    [self.repairPartsModel setupRepairPartsArrayModelWithPartsView:self.partsView];
}
#pragma mark    根据model设置界面
- (void)setupAllDataViewsWithModels{
    if (self.isEditType) {
//        VEHICLE_LIFE_STATUS = self.basicInfoModel.VEHICLE_LIFE_STATUS;
////        _editModel = self.basicInfoModel;
        self.recordModel = self.editModel;
        self.basicInfoView.isEditType = self.isEditType;
        [self.basicInfoView setupBasicInfoViewWithModel:self.basicInfoModel];
    }else{
        //预约转入接车单
        [self.basicInfoView setupBasicInfoViewWithModel:self.basicInfoModel andOtherInfoModel:self.otherInfoModel];
        
        _AppointmentRelevanceState = @"yes";
        
    }
    onwerNo = self.basicInfoModel.OWNER_NO;
    [self getLABOUR_PRICE:self.basicInfoModel.MODEL_CODE];


    
    self.progressDic = [@{@"0":self.basicInfoModel.BOOKING_ORDER_NO?:@"",@"1":self.basicInfoModel.RECEPTION_NO?:@""} mutableCopy];
    [self addProgressHeaderView];
    
    self.selectedRepairTypes = [[self.basicInfoView.repairTypeView.contentText componentsSeparatedByString:@","]mutableCopy];
    [self.selectedRepairTypes removeObjectsInArray:@[@""]];
    
    [self.appearanceCheckView setupAppearanceCheckViewWithCheckAppearanceDownModel:self.checkAppearanceDownModel];
    
    self.selecteActivityView.activityModel = self.activityModel;
    
    if ([ICrEAMTool isVW]){
        self.carePackageView.carePackageModel = self.carePackageModel;
        self.carePackageView.carePackageDownModel = self.carePackageDownModel;
    }
    
    [self.partsView setupPartsViewWithPartsTopModel:self.partsTopModel];
    [self.partsView setupPartsViewWithRepairPartsArrayModel:self.repairPartsModel];
    [self.partsView setupPartsViewWithRepairMaintenancesModel:self.repairEventModel];
    if (self.isAppointmentType) {
        for (ICMRepairPartsModel *model in self.repairPartsModel.TT_RECPTION_PART) {
            model.UPDATE_STATUS = @"A";
        }
        for (ICMRepairMaintenanceModel *model in self.repairEventModel.TT_RECPTION_LABOUR) {
            model.UPDATE_STATUS = @"A";
        }
    }
    [self.partsView refreshInEditType];
    
    self.partsView.repairTypes = self.selectedRepairTypes;
    [self didSelectRepairType:nil];
}
#pragma mark    验证数据完整
- (BOOL)checkDataIsComplete{
    
    if (!self.basicInfoModel.OWNER_NAME || [self.basicInfoModel.OWNER_NAME isEqualToString:@""]) {
        self.showMessage = @"车主姓名";
        [self setupCreateFileView];
        return NO;
    }else if (!self.basicInfoModel.DELIVERER || [self.basicInfoModel.DELIVERER isEqualToString:@""]){
        self.showMessage = @"送修人姓名";
        [self setupCreateFileView];
        return NO;
    }else if (!self.basicInfoModel.DELIVERER_MOBILE || [self.basicInfoModel.DELIVERER_MOBILE isEqualToString:@""]){
        self.showMessage = @"送修人手机";
        [self setupCreateFileView];
        return NO;
    }else
    
    if (!self.basicInfoModel.WASH_TYPE || [self.basicInfoModel.WASH_TYPE isEqualToString:@""]){
        self.showMessage = @"洗车";
        return NO;
    }else if (!self.basicInfoModel.OLD_PART_PROCESS || [self.basicInfoModel.OLD_PART_PROCESS isEqualToString:@""]){
        self.showMessage = @"旧件展示";
        return NO;
    }else if (!self.basicInfoModel.CHECK_SPARE_WHEEL || [self.basicInfoModel.CHECK_SPARE_WHEEL isEqualToString:@""]){
        self.showMessage = @"备胎检查";
        return NO;
    }else if (self.appearanceCheckView.appearancePoints.count && (self.appearanceCheckView.appearanceImages.count + self.appearanceCheckView.appearanceUrls.count == 0)){
        self.showMessage = @"外";
        return NO;
    }else if (self.appearanceCheckView.innerPoints.count && (self.appearanceCheckView.innerImages.count + self.appearanceCheckView.innerUrls.count == 0)){
        self.showMessage = @"内";
        return NO;
    }
    //    else if ((!self.checkAppearanceDownModel.VHCL_GOODS || [self.checkAppearanceDownModel.VHCL_GOODS isEqualToString:@""])&&(!self.checkAppearanceDownModel.VHCL_GOODS_REMARK || [self.checkAppearanceDownModel.VHCL_GOODS_REMARK isEqualToString:@""])){
    //        self.showMessage = @"随车物品";
    //        return NO;
    //    }
    return YES;
}
#pragma mark    构造保存数据
- (NSMutableDictionary *)getRecepetionCarOrderData{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    NSMutableDictionary *basicInfoDic = [NSMutableDictionary dictionary];
    if(IsStrEmpty(self.basicInfoModel.OWNER_NO)){
        self.basicInfoModel.OWNER_NO = onwerNo;
    }
    [basicInfoDic addEntriesFromDictionary:[self.basicInfoModel yy_modelToJSONObject]];
    [basicInfoDic addEntriesFromDictionary:[self.checkAppearanceDownModel yy_modelToJSONObject]];
    [basicInfoDic addEntriesFromDictionary:[self.carePackageDownModel yy_modelToJSONObject]];
    [basicInfoDic addEntriesFromDictionary:[self.partsTopModel yy_modelToJSONObject]];
    
    [dic setObject:[NSArray arrayWithObject:basicInfoDic] forKey:@"TT_RECEPTION_VEHICLE_ORDER"];
#pragma mark 新增快速构造
    NSMutableDictionary *dataDic = [NSMutableDictionary dictionary];
    self.recordModel.MILEAGE = self.basicInfoView.currentMileageView.contentText;
    self.recordModel.SALES_DATE = self.basicInfoView.invoiceDateView.contentText;
    NSDictionary *basicInfoModelDic = [self.recordModel yy_modelToJSONObject];
    
    if (self.recordModel) {
        [dataDic setObject:@[basicInfoModelDic] forKey:@"TM_CUSTOMER_RECORD"];
    }
    
    [dic  addEntriesFromDictionary:dataDic];
    //损伤图片
    [dic addEntriesFromDictionary:[self.checkAppearanceTopModel yy_modelToJSONObject]];
    
    //保养套餐
    if ([ICrEAMTool isVW]){
        [dic addEntriesFromDictionary:[self.carePackageModel yy_modelToJSONObject]];
    }
    
    //活动选择
    [dic addEntriesFromDictionary:[self.activityModel yy_modelToJSONObject]];
    
    //维修项目
    [dic addEntriesFromDictionary:[self.repairEventModel yy_modelToJSONObject]];
    
    //维修零件
    [dic addEntriesFromDictionary:[self.repairPartsModel yy_modelToJSONObject]];
    return dic;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//显示维修项目零件搜索选择页
- (void)showRepairEventAndSearchViewWithRepairType:(NSString *)repairType{
    
}


#pragma mark    扫码成功弹出个人信息面板
- (void)showCustomerInfo{
    [self getCustomerInfo];
}
#pragma mark    点击监控信息按钮
- (void)clickMonitorBtn{
    if (self.carModel.vinNum) {
        MonitorViewController *mvc = [[MonitorViewController alloc] init];
        mvc.vin = self.carModel.vinNum;
        mvc.modalPresentationStyle=UIModalPresentationFormSheet;
        [self presentViewController:mvc animated:YES completion:nil];
    }
}

#pragma mark    点击车辆信息
- (void)clickCarInfoBtn{
    if (self.carModel.vinNum && self.personerModel.OWNER_NO) {
        [self getInfoWithOWNER_NO:self.personerModel.OWNER_NO orVin:self.carModel.vinNum type:@"1"];
    }
}
#pragma mark    点击车主信息
- (void)clickCarOwnerBtn{
    if (self.carModel.vinNum && self.personerModel.OWNER_NO) {
        [self getInfoWithOWNER_NO:self.personerModel.OWNER_NO orVin:self.carModel.vinNum type:@"0"];
    }
}
#pragma mark    点击维修类型
- (void)clickRepairTypeBtn{
    [self.blankView addSubview:self.repairTypeSelectView];
    [self.view addSubview:self.blankView];
}

#pragma mark    牌照输入回调
- (void)licenseDidEndEdit:(ICMTitleTextFeildView *)sender type:(NSString *)type{
    //type0=vin,1=车牌框
    if ([type isEqualToString:@"0"]){
        //判断是正确的vin
        textFtype = 0;
        if ([ICrEAMTool isVinText:sender.contentText]){
            NSString *string = [sender.contentText uppercaseString];//大写
            self.recordModel.VIN = sender.contentText;
            saveModel.VIN = sender.contentText;
            //请求车主车辆
            [self getInfoWithLICENSE:@"" orVin:string];
        }else{
            [self.view showString:@"VIN码输入有误！" forSeconds:1.5];
            return;
        }
        
    }else if ([type isEqualToString:@"1"]){
        //获取车牌号输入框的数据
        textFtype = 1;
        NSString *textFieldAreaAndPlateStr = [self getTextFieldAreaAndPlate];
        if (textFieldAreaAndPlateStr.length < 6) {
            [self.view showString:@"车牌号输入有误！" forSeconds:1.5];
        }else{
            if (IsStrEmpty(self.basicInfoView.vinNumberView.contentText)){
                [self getInfoWithLICENSE:textFieldAreaAndPlateStr orVin:@""];
            }else{
                //是保有客户
                if(_isRetainer == YES){
                    [self judgeAppointmentViewState:textFieldAreaAndPlateStr];
                    
                }else{
                    [self judgeCreateViewState:textFieldAreaAndPlateStr];
                }
                
                
            }
            
        }
        
    }//输入框类型括号


}
#pragma mark    跳转监控信息界面
- (void)clickDetailBtnAtIndex:(NSInteger)index{
    MonitorViewController *mvc = [[MonitorViewController alloc] init];
    mvc.vin = self.carModel.vinNum;
    switch (index) {
        case 0:
            mvc.index = 0;
            break;
        case 1:
            mvc.index = 1;
            break;
        case 2:
            mvc.index = 1;
            break;
        case 3:
            mvc.index = 1;
            break;
        case 4:
            mvc.index = 2;
            break;
        default:
            break;
    }
    mvc.modalPresentationStyle=UIModalPresentationFormSheet;
    [self presentViewController:mvc animated:YES completion:nil];
    
}

#pragma mark 链接预约单号
- (void)linkBookingNo:(NSString *)bookingNoStr
{
    
    [self alertMessage:@"确定关联该预约单?" withSuccessBlock:^{
        self.basicInfoModel.BOOKING_ORDER_NO = bookingNoStr;
        if(bookingNoStr && ![bookingNoStr isEqualToString:@""])
        {   _isContingency = YES;
            [self researchWithRECEPTION_NO:bookingNoStr];
            [self.qrCodeInfoView removeFromSuperview];
            
            
            
        }
        
        
    } failBlock:^{
        
        _isContingency = NO;
        for (int i=0; i<self.cusomerInfo.TT_REPAIR_ORDER.count; i++) {
            RelectiveAppointMentModel *flushmodel=self.cusomerInfo.TT_REPAIR_ORDER[i];
            flushmodel.isSelect=NO;
        }
        
        [self.qrCodeInfoView.appintTableView reloadData];
    }];
    
}

#pragma mark hideAllView
- (void)hideAllView{
    self.qrString = nil;
    [self.blankView removeFromSuperview];
    if (self.CreateFileView) {
        [self.CreateFileView removeFromSuperview];
    }
    if(self.plantCtr.view){
        [self.plantCtr.view removeFromSuperview];
    }
    //从预约查询入口进入的判断
    if([_AppointmentRelevanceState isEqualToString:@"yes"]){
        
        self.customerViewHide = YES;//侧边栏隐藏
        [self.qrCodeInfoView removeFromSuperview];
        
    }else
        
        //接车单入口进入的判断
        if (self.qrCodeInfoView && self.customerViewHide == NO) {
            
            if(_cusomerInfo.TT_REPAIR_ORDER.count == 0){
                self.customerViewHide = YES;//侧边栏隐藏
                [self.qrCodeInfoView removeFromSuperview];
                
            }else if(_isContingency == YES){
                
                
            }else if(_cusomerInfo.TT_REPAIR_ORDER.count >0 && _isContingency == NO ){
                
                [self alertMessage:@"本车辆存在预约单未关联，是否确认关联？" withSuccessBlock:^{
                    
                    
                } failBlock:^{
                    self.customerViewHide = YES;//侧边栏隐藏
                    [self.qrCodeInfoView removeFromSuperview];
                    
                }];
                
            }
            
        }
    
    
    for (UIView *view in self.blankView.subviews) {
        [view removeFromSuperview];
    }
    
}
#pragma mark 移除侧边栏
-(void)removeBroadsideView{
    
    if(_cusomerInfo.TT_REPAIR_ORDER.count == 0){
        [self.blankView removeFromSuperview];
        [self.qrCodeInfoView removeFromSuperview];
        
    }else
        if(_isContingency == YES){
            
            
        }else if(_cusomerInfo.TT_REPAIR_ORDER.count >0 && _isContingency == NO){
            
            [self alertMessage:@"本车辆存在预约单未关联，是否确认关联？" withSuccessBlock:^{
                //            return ;
                
            } failBlock:^{
                
                [self.qrCodeInfoView removeFromSuperview];
                
            }];
            
        }
    
}



- (void)presentVC:(NSNotification *)notification {
    [self presentViewController:[notification object] animated:YES completion:nil];
}
#pragma mark    选择维修类型
- (void)didSelectRepairType:(NSNotification *)notification {
    NSDictionary *dic = notification.object;
    
    if (self.selectedRepairTypes.count) {
        
        NSString *typeText = [ICrEAMTool isVW]?@"常规保养0质量担保保养0一般维修0延保维修0附件安装0二手车认证维修0普通索赔0PDI 索赔0优惠索赔0受控索赔0三包维修0内部车辆维修0内部返工维修0外部返工维修0售前车辆维修0事故车维修0召回行动0技术活动0服务活动":@"常规保养0快速保养0质量担保保养0一般维修0延保维修0附件安装0二手车认证维修0普通索赔0PDI 索赔0优惠维修0受控索赔0三包维修0内部车辆维修0内部返工维修0外部返工维修0售前车辆维修0事故车维修0召回行动0技术活动0服务活动";
        NSArray *types = [typeText componentsSeparatedByString:@"0"];
        NSArray *selectedTypes = [NSArray arrayWithArray:self.selectedRepairTypes];
        [self.selectedRepairTypes removeAllObjects];
        for (NSString *type in types) {
            if ([selectedTypes containsObject:type]) {
                [self.selectedRepairTypes PACA_AddObject:type];
            }
        }
        NSMutableString *temp = [[NSMutableString alloc] initWithString:self.selectedRepairTypes[0]];
        for (int i = 1; i < self.selectedRepairTypes.count; i++) {
            [temp appendString:@","];
            [temp appendString:self.selectedRepairTypes[i]];
        }
        self.basicInfoView.repairTypeView.contentText = temp;
    } else {
        self.basicInfoView.repairTypeView.contentText = @"";
    }
    self.partsView.isPayForType = self.partsView.isPayForType;
    self.isPayForType = self.partsView.isPayForType;
    self.selecteActivityView.isPayForType = self.isPayForType;
    if (self.isPayForType) {
        [self.view showString:@"存在索赔维修类型时，不能打折！" forSeconds:1.5];
    }
    [self.partsView resetRepairTypeButtonWithNotification:dic];
}

#pragma mark    设置界面
-(void)setUpAppICMAppearanceCheckView{
    [self.appearanceCheckView.innerUrls removeAllObjects];
    [self.appearanceCheckView.appearanceUrls removeAllObjects];
    for (ICMPictureModel *model in self.imageModels) {
        switch ([model.DAMAGE_TYPE integerValue]) {
            case ICMEnumDamageType36001001:{
                self.appearanceCheckView.innerImage = model.PIC_PATCH;
            }
                break;
            case ICMEnumDamageType36001002:{
                [self.appearanceCheckView.innerUrls PACA_AddObject:model.PIC_PATCH];
            }
                break;
            case ICMEnumDamageType36001003:{
                self.appearanceCheckView.appearanceImage = model.PIC_PATCH;
            }
                break;
            case ICMEnumDamageType36001004:{
                [self.appearanceCheckView.appearanceUrls PACA_AddObject:model.PIC_PATCH];
            }
                break;
                
            default:
                break;
        }
    }
    [self.appearanceCheckView refreshAppearanceCollectionView];
    [self.appearanceCheckView refreshInnerCollectionView];
}

#pragma mark -- 保存录音接口

- (void)uploadMusic{
    
    ICMRequestManager *manager = [[ICMRequestManager alloc]init];
    [manager startPostMusicWithURL:nil parameters:nil musicUrl:[NSURL fileURLWithPath:micTempPath] inHudView:self.view andResultBlock:^(id data, NSString *failText) {
        if ([data[@"CODE"] integerValue] == 200) {
            
            //保存
            [self.view showString:@"录音上传成功" forSeconds:1.5];
            self.file = data[@"FILE"]?:@"";
            if (self.isSubmit) {
                [self submitISchecked:NO];
            }else{
                [self setupAllDataModels];
                [self saveReceptionCarOrder];
            }
            self.haveRecord = NO;
        }else{
            [self.view showString:@"录音上传失败" forSeconds:1.5];
            if (self.isSubmit) {
                      [self submitISchecked:NO];
            }else{
                [self setupAllDataModels];
                [self saveReceptionCarOrder];
            }
        }
        if (failText) {
            //结算
            [self.view showString:@"录音上传失败" forSeconds:1.5];
            if (self.isSubmit) {
                       [self submitISchecked:NO];
            }else{
                [self setupAllDataModels];
                [self saveReceptionCarOrder];
            }
        }
    }];
}
#pragma mark    上传图片
- (void)UploadImages:(NSDictionary *)images{
//    if(![self checkFormSaveData])
//    {
//        return;
//    }

//    if ([self.basicInfoModel.IN_MILEAGE doubleValue]>[self.basicInfoView.currentMileageView.contentText doubleValue]) {
//        [self.view showString:@"进站里程应大于上次进站里程，请检查！" forSeconds:1.5f];
//        return;
//    }

    [self setupAllDataModels];
    if (![self checkDataIsComplete]) {
        NSString *showMessage = [NSString stringWithFormat:@"%@信息不完整,不能保存!",self.showMessage];
//        [self setupCreateFileView];
        if ([self.showMessage isEqualToString:@"外"]) {
            showMessage = @"外部 :已标记外部损伤信息，请至少拍一张照片！";
        }else if ([self.showMessage isEqualToString:@"内"]){
            showMessage = @"内部：已标记内饰损伤信息，请至少拍一张照片！";
        }
        [self.view showString:showMessage forSeconds:1.5f];
        return;
    }
    
    //    0外部大图 1内部大图 2外部图片数组 3内部图片数组
    ICMRequestManager *manager = [[ICMRequestManager alloc]init];
    [manager startPostImageWithURL:nil parameters:nil images:images inHudView:self.view andResultBlock:^(id data, NSString *failText) {
        
        if ([data[@"CODE"] integerValue] == 200) {
            if ([data[@"FILE_INNER"] isKindOfClass:[NSArray class]]) {
                for (NSString *FILE_INNER in data[@"FILE_INNER"]) {
                    [self.appearanceCheckView.innerUrls PACA_AddObject:FILE_INNER];
                }
            }
            if ([data[@"FILE_OUTER"] isKindOfClass:[NSArray class]]) {
                for (NSString *FILE_OUTER in data[@"FILE_OUTER"]) {
                    [self.appearanceCheckView.appearanceUrls PACA_AddObject:FILE_OUTER];
                }
            }
            
            [self.appearanceCheckView.innerImages removeAllObjects];
            [self.appearanceCheckView.appearanceImages removeAllObjects];
            
            [self.appearanceCheckView setupAppearancePicModelsWithDic:data];
            
            [self clickStopBtn];
            
            if (self.haveRecord) {
                [self clickStopBtn];
                self.haveRecord = NO;
                
            }else{
                [self setupAllDataModels];
                [self saveReceptionCarOrder];
            }
            
        }else{
            [self.view showString:@"上传损伤图片失败" forSeconds:1.5f];
        }
    }];
}
-(void)compriseCustomerByVin:(NSString *)vin andRecordModel:(CustomRecordModel *)recordModel{
    ICMRequestManager *manager = [[ICMRequestManager alloc]init];
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    
    [parameters setObject:@"" forKey:@"LICENSE"];
    [parameters setObject:vin forKey:@"VIN"];
//    [parameters setObject:vin forKey:@"LICENSE"];
//    [parameters setObject:@"" forKey:@"VIN"];
 
    
    [manager startGetRequestWithURL:QueryOwnerByVinLicense parameters:parameters inHudView:self.view andResultBlock:^(id data, NSString *failText) {
        if ([data[@"CODE"] integerValue] == 200) {
            if ([data[@"DATA_STATUS"] integerValue] == 0){
                
                return ;
            }else{
                ICMCarModel *carModel;
                ICMPersonerModel *personerModel;
                NSArray *carModelArray = data[@"TM_VEHICLE"];
                if (![carModelArray isKindOfClass:[NSArray class]]) {
                    return ;
                }
                if (carModelArray.count>0) {
                   carModel = [ICMCarModel yy_modelWithDictionary:data[@"TM_VEHICLE"][0]];

                }
                 NSArray *personerModelArray = data[@"TM_OWNER"];
                 
                 if (![personerModelArray isKindOfClass:[NSArray class]]){
                 return;
                 }
                 if (personerModelArray.count>0) {
                 personerModel = [ICMPersonerModel yy_modelWithDictionary:data[@"TM_OWNER"][0]];
           
                 }
                InformationComparisonViewController *inforCtr= [[InformationComparisonViewController alloc]init];
                inforCtr.carModel=carModel;
                inforCtr.personModel=personerModel;
                inforCtr.model=recordModel;
               
              
                __weak typeof(inforCtr) weakInner=inforCtr;
                inforCtr.sureBlock=^(){
                    [weakInner removeFromParentViewController];
                    [self submitISchecked:YES];
                };
                [inforCtr setDismissBlock:^{
                    
                    [weakInner removeFromParentViewController];
                }];
                [ inforCtr showOnView:[[UIApplication sharedApplication] keyWindow]];
                [self addChildViewController:inforCtr];
            }
        }
        
    }];
    

}
-(void)compriseLicense:(NSString *)license andVin:(NSString *)vin{
    ICMRequestManager *manager = [[ICMRequestManager alloc]init];
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    
        [parameters setObject:license forKey:@"LICENSE"];
        [parameters setObject:@"" forKey:@"VIN"];
 
    [manager startGetRequestWithURL:QueryOwnerByVinLicense parameters:parameters inHudView:self.view andResultBlock:^(id data, NSString *failText) {
        if ([data[@"CODE"] integerValue] == 200) {
            if ([data[@"DATA_STATUS"] integerValue] == 0||[data[@"DATA_STATUS"] integerValue] == 2){
                _plantCtr = [[PlanteNumberChangeViewController alloc]init];
                
                _plantCtr.vin=vin;
                _plantCtr.carArray=nil;
                _plantCtr.ownerArray=nil;
                _plantCtr.linsence=license;
                _plantCtr.view.centerX = self.blankView.frame.size.width/2;
                _plantCtr.sureBlock=^(){
                [self submitISchecked:NO];
                };
                __weak typeof(_plantCtr) weakInner = _plantCtr;
                [_plantCtr setDismissBlock:^{
                    
                    [weakInner removeFromParentViewController];
                }];
                [self addChildViewController:_plantCtr];
                [self.view addSubview:_plantCtr.blankView];
//                [self.view insertSubview:_plantCtr.view aboveSubview:self.blankView];
                
//                [ plantCtr showOnView:[[UIApplication sharedApplication] keyWindow]];
//                [self addChildViewController:plantCtr];
                return ;
            }
            else{
                
                NSArray *carModelArray = data[@"TM_VEHICLE"];
                if (![carModelArray isKindOfClass:[NSArray class]]) {
                    return ;
                }
                
               
                NSArray *personerModelArray = data[@"TM_OWNER"];
                if (![personerModelArray isKindOfClass:[NSArray class]]){
                    return;
                }
                if (license && ![license isEqualToString:@""])
                {
                    
                    _plantCtr = [[PlanteNumberChangeViewController alloc]init];
                    _plantCtr.vin = vin;
                    _plantCtr.carArray = carModelArray;
                    _plantCtr.ownerArray = personerModelArray;
                    _plantCtr.view.centerX = self.blankView.frame.size.width/2;
                    _plantCtr.sureBlock=^(){
                        [self submitISchecked:NO];
                    };
                    __weak typeof(_plantCtr) weakInner=_plantCtr;
                    [_plantCtr setDismissBlock:^{
                        [weakInner removeFromParentViewController];
                                    }];
                    [self addChildViewController:_plantCtr];
                    [self.view addSubview:_plantCtr.blankView];
                                   }
             
            }
        }
    }];
}
#pragma mark    提交接车单
- (void)submitISchecked:(BOOL)isChecked{
    if(![self checkFormSubmitData]){
        return;
    }
    
    ICMRequestManager *manager = [[ICMRequestManager alloc]init];
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:self.getCarNumber forKey:@"RECEPTION_NO"];

        [parameters setObject:isChecked?@"12781001":@"12781002" forKey:@"CHECKED"];
 
    //    self.isSubmit ? [parameters setObject:@"35521002" forKey:@"RECEPTION_STATUS"]:[parameters setObject:@"35521001" forKey:@"RECEPTION_STATUS"];
    ICrEAMUser *user = [ICrEAMUser shareICrEAMUser];
    [parameters setObject:user.employee_NO forKey:@"SERVICE_ADVISOR"];
    [parameters setObject:self.file forKey:@"MP3_FILE"];
    [manager startGetRequestWithURL:SubmitReceptionVehicleOrder parameters:parameters inHudView:self.view  andResultBlock:^(id data, NSString *failText) {
        NSString *states=data[@"STATUS"];
        CustomRecordModel *recordModel;
        id arr=data[@"TM_CUSTOMER_RECORD"];
        if ([arr isKindOfClass:[NSArray class]]) {
            if ([arr[0] isKindOfClass:[NSDictionary class]]) {
                recordModel =[CustomRecordModel yy_modelWithDictionary:arr[0]];
            }
            
        }
        NSString *vin_num=self.basicInfoView.vinNumberView.contentText;
        NSString *lincense_num=[NSString stringWithFormat:@"%@%@",self.basicInfoView.selectAreaView.contentText?:@"",self.basicInfoView.plateNumberView.contentText?:@""];
        if ([states isEqualToString:@"1"]) {
            
            [self compriseCustomerByVin:vin_num?vin_num:self.basicInfoModel.VIN andRecordModel:recordModel];
            return ;
        }
        if ([states isEqualToString:@"2"]) {
            
            [self compriseLicense:lincense_num?lincense_num:self.basicInfoModel.LICENSE andVin:self.carModel.vinNum?self.carModel.vinNum:self.basicInfoModel.VIN];
            return ;
        }
        if ([data[@"CODE"] integerValue] == 200) {
            [self.view showString:@"接车单已提交，不能再修改！" forSeconds:1.5];
            [ICrEAMTool savaOperationReceiptUserName:self.basicInfoModel.DELIVERER carSeries:!StrIsZero_gdm(self.basicInfoModel.SERIES_NAME)?self.basicInfoModel.SERIES_NAME:self.carModel.SERIES_NAME?:@"" licence:self.basicInfoModel.LICENSE status:@"接车单已提交" returnTime:self.partsTopModel.DELIVERY_DATE];
            
            //提交成功后需要更改搜索界面的状态
            [[NSNotificationCenter defaultCenter] postNotificationName:@"getCarStatesHaveChanged" object:nil];
            //提交完 接车日期 今天
            //获取现在时间
            NSDate *currentDate = [NSDate date];
            NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
            [dateFormatter setDateFormat:@"YYYY-MM-dd"];
            NSString *dateString = [dateFormatter stringFromDate:currentDate];
            self.basicInfoModel.DELIVERY_DATE = dateString;
            self.isPrinted = NO;
            
            
            
            //接车单提交后，录音、保存、提交按钮置灰，不能点击，预览、打印按钮可点击。
            UIButton *button0 = self.bottomBarView.bottomButtons[0];
            button0.alpha = 0.5;
            button0.enabled = NO;
            
            UIButton *button1 = self.bottomBarView.bottomButtons[1];
            button1.alpha = 1;
            button1.enabled = YES;
            
            UIButton *button2 = self.bottomBarView.bottomButtons[2];
            button2.alpha = 0.5;
            button2.enabled = NO;
            
            UIButton *button3 = self.bottomBarView.bottomButtons[3];
            button3.alpha = 0.5;
            button3.enabled = NO;
            
            UIButton *button4 = self.bottomBarView.bottomButtons[4];
            button4.alpha = 1;
            button4.enabled = YES;
            
            //提交成功后不能更改
            [self setAllSubViewsDisEnable];
        }
        else
        {
            [self.view showString:@"提交失败！" forSeconds:1.5];
        }
    }];
}
- (void)setAllSubViewsDisEnable{
    self.basicInfoView.userInteractionEnabled = NO;
    self.appearanceCheckView.userInteractionEnabled = NO;
    self.selecteActivityView.userInteractionEnabled = NO;
    self.carePackageView.userInteractionEnabled = NO;
    self.partsView.userInteractionEnabled = NO;
}
#pragma mark 左划监控页信息
- (void)getCustomerInfo{
    ICMRequestManager *manager = [[ICMRequestManager alloc]init];
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    
    [parameters setObject:self.basicInfoView.vinNumberView.contentText forKey:@"VIN"];
    [manager startGetRequestWithURL:@"/INFO_ICREAM_WEB/App/queryVehicleMonitorAll" parameters:parameters inHudView:self.view andResultBlock:^(id data, NSString *failText) {
        if ([data[@"CODE"] integerValue] == 200) {
            if (self.isDisAppear) {
                return;
            }
            self.cusomerInfo.vinNum = self.basicInfoView.vinNumberView.contentText;
            self.cusomerInfo.licenseNum = [NSString stringWithFormat:@"%@%@",self.basicInfoView.selectAreaView.contentText?:@"",self.basicInfoView.plateNumberView.contentText?:@""];
            self.cusomerInfo.customerNum = self.basicInfoView.customerNameView.contentText;
            self.cusomerInfo.phoneNumer = self.basicInfoView.customerPhoneNumberView.contentText;
            [data[@"IS_SANBAO"] isEqualToString:@"是"]? (self.cusomerInfo.isThreeGuarantees = YES) : (self.cusomerInfo.isThreeGuarantees = NO);
            [data[@"HAS_RECALLED"] isEqualToString:@"是"]? (self.cusomerInfo.hasRecall = YES) : (self.cusomerInfo.hasRecall = NO);
            StrIsZero_gdm(data[@"VW_CARD_ID"])?(self.cusomerInfo.VipCount = @"否"):
            (self.cusomerInfo.VipCount = [NSString stringWithFormat:@"%@",data[@"VW_CARD_ID"]]);
            
            NSArray * suggestArray =  data[@"TT_SUGGEST_MAINTAIN_LABOUR"];
            suggestArray.count == 0 ? (self.cusomerInfo.hasLastSuggestion = NO):
            (self.cusomerInfo.hasLastSuggestion = YES);
            NSArray *partArray = data[@"TT_BOOKING_ORDER_PART"];
            partArray.count == 0 ? (self.cusomerInfo.hasReservedData = NO):
            (self.cusomerInfo.hasReservedData = YES);
            NSArray *activityArray = data[@"TT_ACTIVITY"];
            activityArray.count == 0 ? (self.cusomerInfo.hasService = NO):(self.cusomerInfo.hasService = YES);
            NSArray *arr=data[@"TT_BOOKING_ORDER"];
            NSMutableArray *appoints=[NSMutableArray array];
            if (!IsArrEmpty(arr)) {
                if ((self.isEditType || self.isAppointmentType)){
                    for (int i=0; i<arr.count; i++) {
                        RelectiveAppointMentModel *model=[RelectiveAppointMentModel mj_objectWithKeyValues:arr[i]];
                        if ([model.BOOKING_ORDER_NO isEqualToString:self.basicInfoModel.BOOKING_ORDER_NO]) {
                            model.isSelect=YES;
                            [appoints PACA_AddObject:model];
                        }
                        
                        
                    }
                }else{
                    for (int i=0; i<arr.count; i++) {
                        RelectiveAppointMentModel *model=[RelectiveAppointMentModel mj_objectWithKeyValues:arr[i]];
                        if ([model.BOOKING_ORDER_NO isEqualToString:self.basicInfoModel.BOOKING_ORDER_NO]) {
                            model.isSelect=YES;
                        }
                        [appoints PACA_AddObject:model];
                        
                    }
                }
            }
            self.cusomerInfo.TT_REPAIR_ORDER =[appoints mutableCopy];
            //
            id techActiv=data[@"TT_TECH_ACTIVITY"];
            if ([techActiv isKindOfClass:[NSString class]]) {
                if (IsStrEmpty(techActiv)) {
                    self.cusomerInfo.isTechActiv=NO;
                }
            }
            if ([techActiv isKindOfClass:[NSArray class]]) {
                self.cusomerInfo.isTechActiv=IsArrEmpty(techActiv)?NO:YES;
                
            }
            
            //已关联的预约单号
            self.cusomerInfo.bookingNoStr = self.basicInfoModel.BOOKING_ORDER_NO;
            self.qrCodeInfoView.frame = CGRectMake(0, 0, ActualWidth(271), ScreenHeight);
            self.qrCodeInfoView.delegate = self;
            [self.view addSubview:self.blankView];
            [self.view insertSubview:self.qrCodeInfoView aboveSubview:self.blankView];
            self.customerViewHide = NO;//侧边栏已显示
            [self.qrCodeInfoView setupinitData:self.cusomerInfo];
            [UIView animateWithDuration:0.4 animations:^{
                self.qrCodeInfoView.centerX = ActualWidth(271)/2;
            }];
            [self.qrCodeInfoView.appintTableView reloadData];
        }
    }];
    
    
}
#pragma mark    获取车主车辆信息
- (void)getInfoWithOWNER_NO:(NSString *)OWNER_NO orVin:(NSString *)vin type:(NSString *)type{
    ICMRequestManager *manager = [[ICMRequestManager alloc]init];
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:OWNER_NO forKey:@"OWNER_NO"];
    [parameters setObject:vin forKey:@"VIN"];
    [manager startGetRequestWithURL:QueryOwnerDetail parameters:parameters inHudView:self.view andResultBlock:^(id data, NSString *failText) {
        self.carModel = [ICMCarModel yy_modelWithDictionary:data[@"TM_VEHICLE"][0]];
        self.personerModel = [ICMPersonerModel yy_modelWithDictionary:data[@"TM_OWNER"][0]];
        ICMCustomerAndCarViewController *customerAndCar = [ICMCustomerAndCarViewController new];
        customerAndCar.carModel = self.carModel;
        customerAndCar.personerModel = self.personerModel;
        customerAndCar.entrance = [type integerValue];
        [self.navigationController pushViewController:customerAndCar animated:YES];
        
    }];
    
}
#pragma mark    获取车主车辆信息
- (void)getInfoWithLICENSE:(NSString *)LICENSE orVin:(NSString *)vin{
    if(self.moreCarInfoView)
    {
        [self.moreCarInfoView removeFromSuperview];
    }
    
    ICMRequestManager *manager = [[ICMRequestManager alloc]init];
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    if (LICENSE && ![LICENSE isEqualToString:@""]) {
        [parameters setObject:LICENSE forKey:@"LICENSE"];
        [parameters setObject:@"" forKey:@"VIN"];
    }else{
        [parameters setObject:@"" forKey:@"LICENSE"];
        [parameters setObject:vin forKey:@"VIN"];
    }
    [manager startGetRequestWithURL:QueryOwnerByVinLicense parameters:parameters inHudView:self.view andResultBlock:^(id data, NSString *failText) {
        if ([data[@"CODE"] integerValue] == 200) {
            self.basicInfoView.haveChangeCarModel = YES;
            self.basicInfoView.haveChangeVIN = YES;
            if ([data[@"DATA_STATUS"] integerValue] == 0){
                if (!self.isEditType) {
                    [_bottomBarView setButtonEnable:2];
                    _isRetainer = NO;
                    [self setupCreateFileView];
                    
                }
                return ;
            }else{
                if ([data[@"DATA_STATUS"] integerValue] == 2){
                    if (self.isDisAppear) {
                        return;
                    }
                    self.cusomerInfo.vinNum = @"";
                    self.cusomerInfo.licenseNum = @"";
                    self.cusomerInfo.customerNum = @"";
                    self.cusomerInfo.phoneNumer = @"";
                    self.cusomerInfo.isThreeGuarantees = NO;
                    self.cusomerInfo.hasRecall = NO;
                    self.cusomerInfo.VipCount = @"否";
                    self.cusomerInfo.hasLastSuggestion = NO;
                    
                    self.cusomerInfo.hasReservedData = NO;
                    self.cusomerInfo.hasService = NO;
                    NSArray *arr = data[@"TM_CUSTOMER_RECORD"];
                    NSMutableArray *appoints=[NSMutableArray array];
                    
                    if (!IsArrEmpty(arr)) {
                        
                        for (int i=0; i<arr.count; i++) {
                            RelectiveAppointMentModel *model=[RelectiveAppointMentModel mj_objectWithKeyValues:arr[i]];
                            if ([model.BOOKING_ORDER_NO isEqualToString:self.basicInfoModel.BOOKING_ORDER_NO]) {
                                model.isSelect=YES;
                            }
                            [appoints PACA_AddObject:model];
                            
                            
                        }
                    }else{
                        return;
                    }
                    self.cusomerInfo.TT_REPAIR_ORDER =[appoints mutableCopy];
                    //
                    
                    self.cusomerInfo.isTechActiv=NO;
                    
                    
                    //已关联的预约单号
                    self.cusomerInfo.bookingNoStr = self.basicInfoModel.BOOKING_ORDER_NO;
                    self.qrCodeInfoView.frame = CGRectMake(0, 0, ActualWidth(271), ScreenHeight);
                    self.qrCodeInfoView.delegate = self;
                    [self.view addSubview:self.blankView];
                    [self.view insertSubview:self.qrCodeInfoView aboveSubview:self.blankView];
                    self.customerViewHide = NO;//侧边栏已显示
                    [self.qrCodeInfoView setupinitData:self.cusomerInfo];
                    [UIView animateWithDuration:0.4 animations:^{
                        self.qrCodeInfoView.centerX = ActualWidth(271)/2;
                    }];
                    [self.qrCodeInfoView.appintTableView reloadData];
                    return;
                }
                _isRetainer = YES;
                NSArray *carModelArray = data[@"TM_VEHICLE"];
                if (![carModelArray isKindOfClass:[NSArray class]]) {
                    return ;
                }
                
                self.carModel = [ICMCarModel yy_modelWithDictionary:data[@"TM_VEHICLE"][0]];
                onwerNo = self.carModel.OWNER_NO;
                //售前车判断
                if ([_carModel.VEHICLE_LIFE_STATUS isEqualToString:@"25271001"]){
                    self.carModel = [[ICMCarModel alloc]init];
                    _defaultVin = @"";
                    _defaultLisence = @"";
                    self.basicInfoView.vinNumberView.contentText = @"";
                    [_bottomBarView setButtonDisEnable:2];
                    [self alertMessage:@"该车辆为售前车辆，不支持预约和接车流程！"
                             withBlock:^{
                                 [self.CreateFileView removeFromSuperview];
                                 
                             }];
                    return;
                }
                
                else{
                    [_bottomBarView setButtonEnable:2];
                    //保有客户车主，车主手机不能编辑
                    self.basicInfoView.ownerNameView.btnEnAble = NO;
                    self.basicInfoView.ownerNameView.userInteractionEnabled = NO;
                    self.basicInfoView.ownerPhoneNumberView.btnEnAble = NO;
                    self.basicInfoView.ownerPhoneNumberView.userInteractionEnabled = NO;
                    
                }
   
                NSArray *personerModelArray = data[@"TM_OWNER"];
                if (![personerModelArray isKindOfClass:[NSArray class]]){
                    return;
                }
                self.personerModel = [ICMPersonerModel yy_modelWithDictionary:data[@"TM_OWNER"][0]];
                //弹出多信息界面
                if (LICENSE && ![LICENSE isEqualToString:@""])
                {
                    if(carModelArray.count > 1)
                    {
                        int i = 0;
                        int index = -1;
                        if(![self.basicInfoView.vinNumberView.contentText isEqualToString:@""])
                        {
                            for(i = 0;i<carModelArray.count;i++)
                            {
                                ICMCarModel *tempCarModel = [ICMCarModel yy_modelWithDictionary:data[@"TM_VEHICLE"][i]];
                                if([tempCarModel.vinNum isEqualToString:self.basicInfoView.vinNumberView.contentText])
                                {
                                    break;
                                }
                            }
                            index = i;
                        }
                        else
                        {
                            index = -1;
                        }
                        if(i == carModelArray.count)
                        {
                            i = 0;
                            index = -1;
                        }
                        self.carModel = [ICMCarModel yy_modelWithDictionary:data[@"TM_VEHICLE"][i]];
                        self.personerModel = [ICMPersonerModel yy_modelWithDictionary:data[@"TM_OWNER"][i]];
                        
                        self.moreCarInfoView.carArray = [[NSArray alloc] initWithArray:carModelArray];
                        self.moreCarInfoView.personArray = [[NSArray alloc] initWithArray:personerModelArray];
                        self.moreCarInfoView.selectedIndex = index;
                        self.moreCarInfoView.delegate = self;
                        //frame
                        if(carModelArray.count>=6)
                        {
                            [self.moreCarInfoView resetViewFrame:CGRectMake(self.basicInfoView.plateNumberView.frame.origin.x, self.basicInfoView.plateNumberView.frame.origin.y + self.basicInfoView.plateNumberView.frame.size.height, 400, 44*6)];
                        }
                        else
                        {
                            [self.moreCarInfoView resetViewFrame:CGRectMake(self.basicInfoView.plateNumberView.frame.origin.x, self.basicInfoView.plateNumberView.frame.origin.y + self.basicInfoView.plateNumberView.frame.size.height, 400, 44*carModelArray.count)];
                        }
                        
                        
                        [self.basicInfoView addSubview:self.moreCarInfoView];
                    }
                    
                }
                if(carModelArray.count == 1)
                {
                    [self resetViewAfterSelectLicense];
                }
            }
        }
    }];
}

#pragma mark 选择vin后重新给view赋值
- (void)resetViewAfterSelectLicense{

    CustomRecordModel *customModel=[[CustomRecordModel alloc]init];
    customModel.VEHICLE_LIFE_STATUS=self.carModel.VEHICLE_LIFE_STATUS;
    customModel.VIN=self.carModel.vinNum;
    customModel.LICENSE=self.carModel.carNum;
    customModel.BRAND_CODE=self.carModel.brand;
    customModel.BRAND_NAME=self.carModel.brandName;
    customModel.SERIES_CODE=self.carModel.carKei;
    customModel.SERIES_NAME=self.carModel.carKeiName;
    customModel.MODEL_CODE=self.carModel.carType;
    customModel.MODEL_NAME=self.carModel.carTypeName;
    customModel.BUSINESS_KIND=self.carModel.carNature;
    customModel.SALES_DATE=[ICrEAMTool getDateWithTimeInterval:self.carModel.SALES_DATE];
    customModel.OWNER_NO=self.carModel.OWNER_NO;
    customModel.MILEAGE=self.carModel.lastMillions;
    customModel.GENDER=self.personerModel.gender;
    customModel.PROVINCE=self.personerModel.province;
    customModel.CITY=self.personerModel.city;
    customModel.DISTRICT=self.personerModel.district;
    customModel.OWNER_NAME=self.personerModel.ownerName;
    customModel.CONTACTOR_NAME=self.personerModel.CONTACTOR_NAME;
    customModel.CONTACTOR_MOBILE=self.personerModel.CONTACTOR_MOBILE;
    customModel.MOBILE=self.personerModel.phoneNum;
    customModel.OWNER_PROPERTY=self.personerModel.ownerType;
    self.recordModel = customModel;
    self.basicInfoView.vinNumberView.contentText = self.carModel.vinNum;
    self.basicInfoView.currentMileageView.mileageLabel.text = [NSString stringWithFormat:@"%@", self.carModel.lastMillions];
    self.basicInfoView.ownerPhoneNumberView.contentText = self.personerModel.phoneNum;

    if(_isAppointmentType == YES){
        NSString *textFieldAreaAndPlateStr = [self getTextFieldAreaAndPlate];
        if(!IsStrEmpty(textFieldAreaAndPlateStr)){
            [self carChangeAlertMessage:@"车牌发生变化，选择“是”使用新车牌，选“否”选择老车牌！" withSuccessBlock:^{
                NSLog(@"是");
                
                self.carModel.carNum = textFieldAreaAndPlateStr;
                
                
            } failBlock:^{
            
                if (self.carModel.carNum.length>2) {
                    
                    NSString *area = [self.carModel.carNum substringWithRange:NSMakeRange(0, 1)];
                    NSString *plant = [self.carModel.carNum substringWithRange:NSMakeRange(1, self.carModel.carNum.length-1)];
                    unsigned char mCode;
                    sscanf([area UTF8String], "%c", &mCode);
                    
                    if (mCode <= 'Z' && mCode >= 'A') {
                        area = [self.carModel.carNum substringWithRange:NSMakeRange(0, 2)];
                        plant = [self.carModel.carNum substringWithRange:NSMakeRange(2, self.carModel.carNum.length-2)];
                    }
                    self.basicInfoView.selectAreaView.contentText = area;
                    self.basicInfoView.plateNumberView.contentText = plant;
                    
                }

            
            }];

            
        }
    }else{
    
        if (self.carModel.carNum.length>2) {
            
            NSString *area = [self.carModel.carNum substringWithRange:NSMakeRange(0, 1)];
            NSString *plant = [self.carModel.carNum substringWithRange:NSMakeRange(1, self.carModel.carNum.length-1)];
            unsigned char mCode;
            sscanf([area UTF8String], "%c", &mCode);
            
            if (mCode <= 'Z' && mCode >= 'A') {
                area = [self.carModel.carNum substringWithRange:NSMakeRange(0, 2)];
                plant = [self.carModel.carNum substringWithRange:NSMakeRange(2, self.carModel.carNum.length-2)];
            }
            self.basicInfoView.selectAreaView.contentText = area;
            self.basicInfoView.plateNumberView.contentText = plant;
            self.basicInfoView.vinNumberView.contentText = self.carModel.vinNum;
            self.basicInfoView.currentMileageView.mileageLabel.text = [NSString stringWithFormat:@"%@", self.carModel.lastMillions];
            self.basicInfoView.ownerPhoneNumberView.contentText = self.personerModel.phoneNum;
            
        }

    
    
    
    }

    self.basicInfoView.personModel = self.personerModel;
    self.basicInfoView.invoiceDateView.contentText = [ICrEAMTool getDateWithTimeInterval:self.carModel.SALES_DATE];
    self.basicInfoView.carTypeView.contentText = [NSString stringWithFormat:@"%@|%@",self.carModel.carType,self.carModel.carTypeName];
    self.basicInfoView.carTypeView.noStr = self.carModel.carType;
    if(!self.basicInfoModel)
    {
        self.basicInfoModel = [[ICMBasicInfoModel alloc] init];
    }
    self.basicInfoModel.MODEL_NAME = self.carModel.carTypeName;

    self.basicInfoModel.OWNER_NO = onwerNo;
    self.basicInfoView.ownerNameView.contentText = self.personerModel.ownerName;
    self.basicInfoView.ownerTypeView.contentText = [ICrEAMTool getCodeModelForCode:self.personerModel.ownerType].desc;;
    if (!(self.isEditType || self.isAppointmentType)) {
        self.basicInfoView.ownerPhoneNumberView.contentText = self.personerModel.phoneNum;
        //        self.basicInfoView.currentMileageView.contentText = self.carModel.currentMillions;
        
        //        self.basicInfoView.current_mile = [self.carModel.currentMillions integerValue];
        //上次出厂里程
        self.basicInfoView.currentMileageView.mileageLabel.text = [NSString stringWithFormat:@"%@", self.carModel.lastMillions];
        self.basicInfoView.vinNumberView.contentText = self.carModel.vinNum;
    }
    
        if (self.isDisAppear) {
        return;
    }
    

    //送修人信息
    if (!(self.isEditType || self.isAppointmentType)) {
        self.basicInfoView.customerNameView.contentText = self.personerModel.CONTACTOR_NAME;
        self.basicInfoView.customerPhoneNumberView.contentText = self.personerModel.CONTACTOR_MOBILE;
        
        if (!self.personerModel.CONTACTOR_NAME || [self.personerModel.CONTACTOR_NAME isEqualToString:@""]) {
            self.basicInfoView.customerNameView.contentText = self.personerModel.ownerName;
        }
        if (!self.personerModel.CONTACTOR_MOBILE || [self.personerModel.CONTACTOR_MOBILE isEqualToString:@""]) {
            self.basicInfoView.customerPhoneNumberView.contentText = self.personerModel.phoneNum;
        }
        
    }
    
    self.partsView.workingUnitPriceView.contentText = [NSString stringWithFormat:@"%.2f",[self.carModel.LABOUR_PRICE floatValue]];
    [self showCustomerInfo];
    //头部跳转用赋值
    super.super_VIN = self.carModel.vinNum;
    super.super_owner_no = self.carModel.OWNER_NO;
}



- (void)setGetCarNumber:(NSString *)getCarNumber{
    _getCarNumber = getCarNumber;
    self.basicInfoView.RECEPTION_NO = getCarNumber;
}

- (BOOL)isPayForType{
    return self.partsView.isPayForType;
}



#pragma mark -- 录音功能

- (AVAudioRecorder *)audioRecorder{
    if (!_audioRecorder) {
        //创建录音文件保存路径
        NSURL *url = [NSURL URLWithString:micTempPath];
        
        //创建录音格式设置
        NSDictionary *setting = [self getAudioSetting];
        
        //创建录音机
        NSError *error = nil;
        _audioRecorder = [[AVAudioRecorder alloc] initWithURL:url settings:setting error:&error];
        _audioRecorder.delegate = self;
        [_audioRecorder peakPowerForChannel:0];
        _audioRecorder.meteringEnabled = YES;//如果要监控声波则必须设置为YES
        if (error) {
            
            self.bottomBarView.recorderLabel.text = @"录 音";
            [self.view showString:@"录音失败" forSeconds:1.5];
            self.haveRecord = NO;
            return nil;
        }
    }
    return _audioRecorder;
}

- (AVAudioPlayer *)audioPlayer {
    if (!_audioPlayer) {
        NSURL *url = [NSURL URLWithString:micTempPath];
        NSError *error = nil;
        _audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:&error];
        _audioPlayer.numberOfLoops = 0;
        if (![_audioPlayer prepareToPlay]) {
            
        };
        if (error) {
            
            return nil;
        }
    }
    return _audioPlayer;
}

- (void)setAudioAndPlayer{
    [self setAudioSession];
    //    self.couldRecord = [self.audioRecorder prepareToRecord];
}

- (void)setAudioSession {
    
    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    
    if ([audioSession respondsToSelector:@selector(requestRecordPermission:)]) {
        [audioSession performSelector:@selector(requestRecordPermission:) withObject:^(BOOL granted) {
            if (granted) {
                NSError *error;
                [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
                if (error) {
                    
                    error = nil;
                }
                [audioSession setActive:YES error:&error];
                if (error) {
                    
                }
                self.couldRecord = YES;
            } else {
                self.couldRecord = NO;
            }
        }];
    }
    
}

- (NSDictionary *)getAudioSetting{
    NSMutableDictionary *dicM = [NSMutableDictionary dictionary];
    //设置录音格式
    [dicM setObject:@(kAudioFormatMPEG4AAC) forKey:AVFormatIDKey];
    //设置录音采样率，8000是电话采样率，对于一般录音已经够了
    [dicM setObject:@(8000) forKey:AVSampleRateKey];
    //设置通道,这里采用单声道
    [dicM setObject:@(1) forKey:AVNumberOfChannelsKey];
    //每个采样点位数,分为8、16、24、32
    [dicM setObject:@(8) forKey:AVLinearPCMBitDepthKey];
    //    //是否使用浮点数采样
    //    [dicM setObject:@(YES) forKey:AVLinearPCMIsFloatKey];
    [dicM setObject:@(AVAudioQualityMax) forKey:AVEncoderAudioQualityKey];
    return dicM;
}

- (void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag {
    
    [self uploadMusic];
}

- (void)audioRecorderEncodeErrorDidOccur:(AVAudioRecorder *)recorder error:(NSError * __nullable)error {
    [self setupAllDataModels];
    [self saveReceptionCarOrder];
    
}

- (void)clickRecordBtn{
    if (self.couldRecord){
        [self.audioRecorder record];
    }
}

- (void)clickStopBtn{
    self.bottomBarView.recorderLabel.text = @"录 音";
    [self.audioRecorder stop];
    
}

- (void)clickPauseBtn{
    if (self.couldRecord){
        [self.audioRecorder pause];
    }
}

#pragma mark 车型未选择message
- (void)getCarShowMessage:(NSNotification *)notification
{
    [self.view showString:@"车型未选择!" forSeconds:1.5];
}

#pragma mark 快速建档 message
- (void)createFileMsgNotifacation:(NSNotification *)notification
{
    NSDictionary *dic = notification.userInfo;
    NSString *errMsg = dic[@"msg"];
    if(self.CreateFileView)
        [self.CreateFileView showString:errMsg forSeconds:1.5];
}

#pragma mark 检查是否可删除维修类型
- (BOOL)canRemoveItem:(NSString *)itemStr
{
    BOOL existsItems = NO;
    //检查项目
    NSArray *tempArray1 = self.repairEventModel.TT_RECPTION_LABOUR;
    for(int i = 0;i<tempArray1.count;i++)
    {
        ICMRepairMaintenanceModel *tempModel = tempArray1[i];
        if([tempModel.REPAIR_TYPE_NAME isEqualToString:itemStr])
        {
            existsItems = YES;
        }
    }
    if(existsItems)
    {
        [self.repairTypeSelectView showString:@"存在该维修类型的项目或零件，不能删除!" forSeconds:2];
        return NO;
    }
    //检查零件
    NSArray *tempArray2 = self.repairPartsModel.TT_RECPTION_PART;
    for(int i = 0;i<tempArray2.count;i++)
    {
        ICMRepairPartsModel *tempModel = tempArray2[i];
        if([tempModel.REPAIR_TYPE_NAME isEqualToString:itemStr])
        {
            existsItems = YES;
        }
    }
    if(existsItems)
    {
        [self.repairTypeSelectView showString:@"存在该维修类型的项目或零件，不能删除!" forSeconds:2];
        return NO;
    }
    return YES;
}

#pragma mark 关联预约单
- (void)researchWithRECEPTION_NO:(NSString *)RECEPTION_NO{
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:RECEPTION_NO forKey:@"ORDER_ID"];
    ICMRequestManager *manager = [[ICMRequestManager alloc]init];
    [manager startGetRequestWithURL:BookingOrderDetils parameters:parameters inHudView:self.view andResultBlock:^(id data, NSString *failText) {
        if ([data[@"CODE"] integerValue] == 200) {
            if (IsArr(data[@"TT_BOOKING_OEDER"])) {
                
                ICMBasicInfoModel *tempBasicInfoModel = [ICMBasicInfoModel yy_modelWithDictionary:data[@"TT_BOOKING_OEDER"][0]];
                
                ICMAppointmentOtherInfoModel *tempBasicOtherModel = [ICMAppointmentOtherInfoModel yy_modelWithDictionary:data[@"TT_BOOKING_OEDER"][0]];
                ICMPartsTopModel *tempPartsTopModel = [ICMPartsTopModel yy_modelWithDictionary:data[@"TT_BOOKING_OEDER"][0]];
                
                ICMRepairMaintenancesModel *tempMaintenancesModel = [ICMRepairMaintenancesModel yy_modelWithDictionary:data];
                [tempMaintenancesModel createRepairMaintenanceBookingModel];
                
                ICMRepairPartsArrayModel *tempPartsArrayModel = [ICMRepairPartsArrayModel yy_modelWithDictionary:data];
                [tempPartsArrayModel createRepairPartsBookingModel];
                
                ICMActivityModel *tempActivityModel = [ICMActivityModel yy_modelWithDictionary:data];
                [tempActivityModel createActivityItemBookingModel];
                
                //非保有客户
                if(IsStrEmpty(tempBasicInfoModel.OWNER_NO)){
                    self.isRetainer = YES;
                }else{
                    self.isRetainer = NO;
                }
                self.BUSINESS_KIND = tempBasicInfoModel.BUSINESS_KIND;
                
                self.carModel = [ICMCarModel yy_modelWithDictionary:data[@"TT_BOOKING_OEDER"][0]];

                self.personerModel = [ICMPersonerModel yy_modelWithDictionary:data[@"TT_BOOKING_OEDER"][0]];
                self.isAppointmentType = YES;
                self.basicInfoModel = tempBasicInfoModel;
                self.basicInfoModel.BUSINESS_DESC = @"";
                self.otherInfoModel = tempBasicOtherModel;
                self.otherInfoModel.REMARK = @"";
                self.partsTopModel = tempPartsTopModel;
                self.repairEventModel = tempMaintenancesModel;
                self.repairEventModel.TT_RECPTION_LABOUR = tempMaintenancesModel.TT_BOOKING_ORDER_LABOUR;
                self.repairPartsModel = tempPartsArrayModel;
                self.repairPartsModel.TT_RECPTION_PART = tempPartsArrayModel.TT_BOOKING_ORDER_PART;
                
                //填补beas model空缺
                NSMutableArray *CUSTOMER_RECORDarray = [NSMutableArray arrayWithArray:data[@"TM_CUSTOMER_RECORD"]];
                
                if (IsArr(data[@"TM_CUSTOMER_RECORD"]) && CUSTOMER_RECORDarray.count>0){
                 CustomRecordModel *recordModel = [CustomRecordModel mj_objectWithKeyValues:data[@"TM_CUSTOMER_RECORD"][0]];
                    self.recordModel = recordModel;
                    self.basicInfoModel.MOBILE = recordModel.MOBILE;

                }
               
               //                self.basicInfoModel.VEHICLE_LIFE_STATUS = customerModel.VEHICLE_LIFE_STATUS;
                [self setupBigScrollView];
                
                self.selecteActivityView.isEditType = self.isEditType;
                self.selecteActivityView.isAppointmentType = self.isAppointmentType;
                self.selecteActivityView.otherInfoModel = self.otherInfoModel;
                self.selecteActivityView.vinNumberView = self.basicInfoView.vinNumberView;
                self.partsView.carTypeView = self.basicInfoView.carTypeView;
                self.carePackageView.carTypeView = self.basicInfoView.carTypeView;
                self.basicInfoView.currentMileageView.contentText = [NSString stringWithFormat:@"%ld", [tempBasicInfoModel.IN_MILEAGE integerValue]];
                
                self.basicInfoView.ownerPhoneNumberView.contentText = self.basicInfoModel.MOBILE?: self.basicInfoModel.OWNER_MOBILE;
                
                if (self.isIn) {
                    //已进站
                    for (int i = 0; i < self.bottomBarView.bottomButtons.count; i++) {
                        if (i != 1) {
                            UIButton *button = self.bottomBarView.bottomButtons[i];
                            button.alpha = 0.5;
                            button.enabled = NO;
                        }
                    }
                }
                else
                {
                    //未进站
                    //新建及编辑接车单时 只有 录音、保存按钮可点击
                    UIButton *button1 = self.bottomBarView.bottomButtons[1];
                    button1.alpha = 0.5;
                    button1.enabled = NO;
                    
                    UIButton *button3 = self.bottomBarView.bottomButtons[3];
                    button3.alpha = 0.5;
                    button3.enabled = NO;
                    
                    UIButton *button4 = self.bottomBarView.bottomButtons[4];
                    button4.alpha = 0.5;
                    button4.enabled = NO;
                }
                //头部跳转用赋值
                super.super_VIN = self.basicInfoModel.VIN;
                super.super_owner_no = self.basicInfoModel.OWNER_NO;
                
                self.isPrinted = YES;
                NSArray *array = data[@"TM_CUSTOMER_RECORD"];
                
                if(array.count < 1){
                    
                }else{
                
                    if(IsStrEmpty(_basicInfoModel.VIN)||IsStrEmpty(_basicInfoModel.OWNER_NAME)||IsStrEmpty(_basicInfoModel.OWNER_MOBILE)||IsStrEmpty(_basicInfoModel.OWNER_PROPERTY)||IsStrEmpty(_basicInfoModel.SALES_DATE)||IsStrEmpty(_basicInfoModel.MODEL_CODE)||IsStrEmpty(_basicInfoModel.MODEL_NAME)){
                        
                        CustomRecordModel *model=[CustomRecordModel yy_modelWithDictionary:data[@"TM_CUSTOMER_RECORD"][0]];
                        self.recordModel=model;
                        
                        self.CreateFileView = [ICMCreateFileView creatICMCreateFileViewWithFrame:CGRectMake((ScreenWidth-ActualWidth(940))/2, (ScreenHeight-ActualHeight(490))/2, ActualWidth(940), ActualHeight(490)) withType:2];
                        
                        self.CreateFileView.type = 2;
                        self.CreateFileView.customModel=model;
                        self.CreateFileView.dateView.contentText = [ICrEAMTool getDateWithTimeInterval:model.SALES_DATE];
                        self.CreateFileView.delegate = self;
                        self.CreateFileView.hidden = NO;
                        self.blankView.hidden = NO;
                        [self.view addSubview:self.blankView];
                        [self.view addSubview:self.CreateFileView];
                        
                    }

                
                }
                
                [self hideAllView];
                
                
                
                
            }
        }
    }];
}


- (MoreCarInfoView *)moreCarInfoView
{
    if(!_moreCarInfoView)
    {
        _moreCarInfoView = [[MoreCarInfoView alloc] init];
    }
    return _moreCarInfoView;
}

#pragma mark MoreCarInfoViewDelegate
//点击了那条数据
- (void)didClickedCellAtIndex:(NSInteger)index WithVIN:(NSString *)vin
{
    [self getInfoWithLICENSE:@"" orVin:vin];
    
    if(self.moreCarInfoView)
    {
        [self.moreCarInfoView removeFromSuperview];
        self.moreCarInfoView = nil;
    }
    
}

#pragma mark    获取活动数据
//参数 当前时间
//参数 车型code
-(void)getActivity{
    //获取现在时间
    NSDate *currentDate = [NSDate date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"YYYY-MM-dd"];
    NSString *dateString = [dateFormatter stringFromDate:currentDate];
    if(!self.selecteActivityView.vinNumberView.contentText || [self.selecteActivityView.vinNumberView.contentText isEqualToString:@""])
    {
        [self.selecteActivityView.activityModels removeAllObjects];
        [self.selecteActivityView.selectedIndexs removeAllObjects];
        [self.selecteActivityView.activityTableView reloadData];
//        [[NSNotificationCenter defaultCenter] postNotificationName:@"GetCarShowMessage" object:self];
        
        return;
    }
    
    
    ICMRequestManager *manager = [[ICMRequestManager alloc]init];
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:self.selecteActivityView.vinNumberView.contentText forKey:@"VIN"];
    [parameters setObject:dateString forKey:@"IN_TIME"];
    [manager startGetRequestWithURL:QureyActivity parameters:parameters inHudView:self.view andResultBlock:^(id data, NSString *failText) {
        
        if ([data[@"CODE"] integerValue] == 200) {
            NSArray *dataArray = data[@"TT_ACTIVITY"];
            if (dataArray.count != 0 && dataArray) {
                
            }else{
                if(self.actMsgBgView2)
                {
                    [self.actMsgBgView2 removeFromSuperview];
                }
                [self.selecteActivityView addSubview:self.actMsgBgView2];
                if(self.actMsgLabel2)
                {
                    [self.actMsgLabel2 removeFromSuperview];
                }
                [self.actMsgBgView2 addSubview:self.actMsgLabel2];
                
            }
        }
        else
        {
            if(self.actMsgBgView2)
            {
                [self.actMsgBgView2 removeFromSuperview];
            }
            [self.selecteActivityView addSubview:self.actMsgBgView2];
            if(self.actMsgLabel2)
            {
                [self.actMsgLabel2 removeFromSuperview];
            }
            [self.actMsgBgView2 addSubview:self.actMsgLabel2];
        }
        
        [self.selecteActivityView getActivityWithData:data];
    }];
}

#pragma mark    获取套餐数据
- (void)getCarePackage{
    if (![ICrEAMTool isVW]) {
        return;
    }
    if (!self.carePackageView.modelCode || [self.carePackageView.modelCode isEqualToString:@""]) {
        [self.view showString:@"车型还没有填写!" forSeconds:1.5];
        return;
    }
    NSDictionary *params = @{@"MODEL_CODE":self.carePackageView.modelCode};
    [[ICMRequestManager alloc] startGetRequestWithURL:[NSString stringWithFormat:@"/INFO_ICREAM_WEB/App/querySpecPackage"] parameters:params inHudView:self.view andResultBlock:^(id data, NSString *failText) {
        [self.carePackageView getCarePackageWithData:data];
    }];
}

-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    if(_customerViewHide == YES){
        
    }else{
        
        [self hideAllView];
    }
    
}

-(void)judgeCreateViewState:(NSString *)textFieldAreaAndPlateStr{
    changeCarNumberType = 1;
    if ([ICrEAMTool isVinText:self.basicInfoView.vinNumberView.contentText]){
        //判断是否修改车牌
        if(IsStrEmpty(self.recordModel.LICENSE)){
         
        }else{
            if(![textFieldAreaAndPlateStr isEqualToString:self.recordModel.LICENSE]){
//                [self addPlantAlter:textFieldAreaAndPlateStr];
                [self carChangeAlertMessage:@"车牌发生变化，选择“是”使用新车牌，选“否”选择老车牌！" withSuccessBlock:^{
                    NSLog(@"是");
                    //用新车牌
                    self.carModel.carNum = textFieldAreaAndPlateStr;
                    if(_isEditType == YES){
                        self.recordModel.LICENSE = textFieldAreaAndPlateStr;
                    }
                    
                } failBlock:^{
                    //复原车牌
                    if(IsStrEmpty(self.carModel.carNum)){
                        //快速建档中没有车牌时 输入车牌的回调取值
                        NSString *createSubAreaStr = [self getModelAreaStr:self.recordModel.LICENSE];
                        NSString *createPlateStr = [self getModelPlateStr:self.recordModel.LICENSE];
                        self.basicInfoView.selectAreaView.contentText = createSubAreaStr;
                        self.basicInfoView.plateNumberView.contentText = createPlateStr;
                        
                    }else{
                        NSString *modelAreaStr = [self getModelAreaStr:self.carModel.carNum];
                        NSString *modelPlateStr = [self getModelPlateStr:self.carModel.carNum];
                        self.basicInfoView.selectAreaView.contentText = modelAreaStr;
                        self.basicInfoView.plateNumberView.contentText = modelPlateStr;
                        
                    }}];
            }
            
            
        }
        
        
        
    }
    
    
    
}

//接车界面判断车牌变更
-(void)judgeAppointmentViewState:(NSString *)textFieldAreaAndPlateStr{
    changeCarNumberType = 2;
    if([ICrEAMTool isVinText:self.basicInfoView.vinNumberView.contentText]){
        //判断是否修改车牌
        if(![textFieldAreaAndPlateStr isEqualToString:self.carModel.carNum]){
            NSLog(@"改车牌了");
            [self carChangeAlertMessage:@"车牌发生变化，选择“是”使用新车牌，选“否”选择老车牌！" withSuccessBlock:^{
                NSLog(@"是");
                //用新车牌
                self.carModel.carNum = textFieldAreaAndPlateStr;
            } failBlock:^{
                //复原车牌
                if(IsStrEmpty(self.carModel.carNum)){
                    //快速建档中没有车牌时 输入车牌的回调取值
                    NSString *createSubAreaStr = [self.recordModel.LICENSE substringToIndex:1];
                    NSString *createPlateStr = [self.recordModel.LICENSE substringFromIndex:1];
                    self.basicInfoView.selectAreaView.contentText = createSubAreaStr;
                    self.basicInfoView.plateNumberView.contentText = createPlateStr;
                }else{
                    NSString *modelAreaStr = [self getModelAreaStr:self.carModel.carNum];
                    NSString *modelPlateStr = [self getModelPlateStr:self.carModel.carNum];
                    self.basicInfoView.selectAreaView.contentText = modelAreaStr;
                    self.basicInfoView.plateNumberView.contentText = modelPlateStr;
                    
                }}];
//            [self addPlantAlter:textFieldAreaAndPlateStr];

        }
        
    }//最外面的if括号
    
}

-(void)judgeGetCarViewStateOfExistAreaAndPlateStr:(NSString *)textFieldAreaAndPlateStr{
    changeCarNumberType = 3;
    //判断是否修改车牌
    if(IsStrEmpty(textFieldAreaAndPlateStr)){
        [self resetViewAfterSelectLicense];
    }else{
        
        if(![textFieldAreaAndPlateStr isEqualToString:self.carModel.carNum]){
            NSLog(@"改车牌了");
//            [self addPlantAlter:textFieldAreaAndPlateStr];
            [self carChangeAlertMessage:@"车牌发生变化，选择“是”使用新车牌，选“否”选择老车牌！" withSuccessBlock:^{
                NSLog(@"是");
                //用新车牌
                self.carModel.carNum = textFieldAreaAndPlateStr;
                [self resetViewAfterSelectLicense];
                
            } failBlock:^{
                
                [self resetViewAfterSelectLicense];
                
            }];
        }
        
    }
}





-(void)getMoreCarInfoViewWithLICENSE:(NSString *)LICENSE andCarArray:(NSArray *)carArray andData:(id)data andPersonerModelArray:(NSArray *)personerModelArray{
    
    //弹出多信息界面
    if (LICENSE && ![LICENSE isEqualToString:@""])
    {
        if(carArray.count > 1)
        {
            int i = 0;
            int index = -1;
            if(![self.basicInfoView.vinNumberView.contentText isEqualToString:@""])
            {
                for(i = 0;i<carArray.count;i++)
                {
                    ICMCarModel *tempCarModel = [ICMCarModel yy_modelWithDictionary:data[@"TM_VEHICLE"][i]];
                    if([tempCarModel.vinNum isEqualToString:self.basicInfoView.vinNumberView.contentText])
                    {
                        break;
                    }
                }
                index = i;
            }
            else
            {
                index = -1;
            }
            if(i == carArray.count)
            {
                i = 0;
                index = -1;
            }
            self.carModel = [ICMCarModel yy_modelWithDictionary:data[@"TM_VEHICLE"][i]];
            self.personerModel = [ICMPersonerModel yy_modelWithDictionary:data[@"TM_OWNER"][i]];
            
            self.moreCarInfoView.carArray = [[NSArray alloc] initWithArray:carArray];
            self.moreCarInfoView.personArray = [[NSArray alloc] initWithArray:personerModelArray];
            self.moreCarInfoView.selectedIndex = index;
            self.moreCarInfoView.delegate = self;
            //frame
            if(carArray.count>=6)
            {
                [self.moreCarInfoView resetViewFrame:CGRectMake(self.basicInfoView.plateNumberView.frame.origin.x, self.basicInfoView.plateNumberView.frame.origin.y + self.basicInfoView.plateNumberView.frame.size.height, 400, 44*6)];
            }
            else
            {
                [self.moreCarInfoView resetViewFrame:CGRectMake(self.basicInfoView.plateNumberView.frame.origin.x, self.basicInfoView.plateNumberView.frame.origin.y + self.basicInfoView.plateNumberView.frame.size.height, 400, 44*carArray.count)];
            }
            
            
            [self.basicInfoView addSubview:self.moreCarInfoView];
        }
        
    }
    
    
}
-(NSString*)getTextFieldAreaAndPlate{
    
    //获取车牌号输入框的数据
    NSString *areaAndPlant = [NSString stringWithFormat:@"%@%@",self.basicInfoView.selectAreaView.contentText?:@"",self.basicInfoView.plateNumberView.contentText?:@""];
    
    return areaAndPlant;
    
}

-(NSString *)getTextFieldAreaStr{
    NSString *areaStr = self.basicInfoView.selectAreaView.contentText;
    return areaStr;
}

-(NSString *)getTextFieldPlateStr{
    NSString *plateStr = self.basicInfoView.plateNumberView.contentText;
    return plateStr;
}

-(NSString *)getModelAreaStr:(NSString *)AreaAndPlate{
    NSString *subAreaStr = [AreaAndPlate substringToIndex:1];
    return subAreaStr;
}
-(NSString *)getModelPlateStr:(NSString *)AreaAndPlate{
    NSString *subPlateStr = [AreaAndPlate substringFromIndex:1];
    return subPlateStr;
}
-(BOOL)submitCheck{
    
    if([self.basicInfoModel.VEHICLE_LIFE_STATUS isEqualToString:@"25271002"]){
        if(IsStrEmpty(self.basicInfoModel.OWNER_NAME)){
            [self.view showString:@"车主姓名为空，请检查!" forSeconds:1.5f];
            return NO;
            
        }
        
    }


    return YES;

}

#pragma mark    保存验证数据
- (BOOL)checkFormSaveData{
    //去空格
    NSString *OWNER_MOBILE = self.basicInfoModel.OWNER_MOBILE;
    NSString *DELIVERER_MOBILE = self.basicInfoModel.DELIVERER_MOBILE;
    self.basicInfoModel.OWNER_MOBILE = [ICrEAMTool trimWhitespace:OWNER_MOBILE];
    self.basicInfoModel.DELIVERER_MOBILE = [ICrEAMTool trimWhitespace:DELIVERER_MOBILE];
    
    self.basicInfoView.ownerPhoneNumberView.contentText = [ICrEAMTool trimWhitespace:self.basicInfoView.ownerPhoneNumberView.contentText];
    self.basicInfoView.customerNameView.contentText = [ICrEAMTool trimWhitespace:self.basicInfoView.customerNameView.contentText];
    
    if([self.basicInfoModel.OWNER_PROPERTY isEqualToString:@"11901002"]){
        self.basicInfoModel.OWNER_NAME = [ICrEAMTool trimWhitespace:self.basicInfoView.ownerNameView.contentText];
        self.basicInfoModel.DELIVERER = [ICrEAMTool trimWhitespace:self.basicInfoView.customerNameView.contentText];
        self.basicInfoView.ownerNameView.contentText = [ICrEAMTool trimWhitespace:self.basicInfoView.ownerNameView.contentText];
        self.basicInfoView.customerNameView.contentText = [ICrEAMTool trimWhitespace:self.basicInfoView.customerNameView.contentText];
        
    }
    
    if([self.personerModel.ownerType isEqualToString:@"11901002"]){
        if([ICrEAMTool isVaildRealName:self.basicInfoView.ownerNameView.contentText] == NO ){
            
            [self.view showString:@"车主姓名有误，请修改后保存！" forSeconds:1.5];
            return NO;
        }
    }
    if([ICrEAMTool validateMobile:self.basicInfoView.ownerPhoneNumberView.contentText] == NO){
        
        [self.view showString:@"车主手机号有误，请修改后保存！" forSeconds:1.5];
        return NO;
    }

    if([self.personerModel.ownerType isEqualToString:@"11901001"]){
        if([ICrEAMTool isVaildCompanyName:self.basicInfoView.ownerNameView.contentText] == NO ){
            
            [self.view showString:@"公司名称有误，请修改后保存！" forSeconds:1.5];
            return NO;
        }
    }

    if([ICrEAMTool isVaildRealName:self.basicInfoView.customerNameView.contentText] == NO ){
        
        [self.view showString:@"送修人姓名有误，请修改后保存！" forSeconds:1.5];
        return NO;
    }
    if([ICrEAMTool validateMobile:self.basicInfoView.customerPhoneNumberView.contentText] == NO){
        
        [self.view showString:@"送修人手机号有误，请修改后保存！" forSeconds:1.5];
        return NO;
    }


        if(IsStrEmpty(_recordModel.VEHICLE_LIFE_STATUS)||[_recordModel.VEHICLE_LIFE_STATUS isEqualToString:@"0"]){
            [self showAlterWhitErrorStr:@"车辆生命周期为空，请检查!"];
                return NO;
        }else{
            //上次里程
            NSInteger mileage = [self.basicInfoView.currentMileageView.contentText integerValue];
            
            if([self.carModel.lastMillions integerValue] > mileage || [self.basicInfoView.currentMileageView.contentText integerValue]>mileage) {
                [self alertMessage:@"当前进站里程小于上次进站里程，请检查！"
                         withBlock:^{
                             
                         }];
                
                
                return NO;
                
            }else if ([self.basicInfoView.currentMileageView.contentText integerValue]  == 0 ){
                
                [self alertMessage:@"请检查当前行驶里程！"
                         withBlock:^{
                         }];
                
                return NO;
                
            }else if([self.carModel.lastMillions integerValue] == 0 && mileage == 0){
                
                
                [self alertMessage:@"当前进站里程与上次进站里程相同，请检查！"
                         withBlock:^{
                         }];
                return NO;
                
            }

            
            if(IsStrEmpty(_recordModel.VIN)&&IsStrEmpty(self.basicInfoView.vinNumberView.contentText)){
                [self showAlterWhitErrorStr:@"VIN为空，请检查!"];
                return NO;
            }
            if(IsStrEmpty(_recordModel.LICENSE)&&IsStrEmpty([self getTextFieldAreaAndPlate])){
                [self showAlterWhitErrorStr:@"车牌为空，请检查!"];
                return NO;
            }
            if(IsStrEmpty(_recordModel.MODEL_CODE)){
                [self showAlterWhitErrorStr:@"车型代码为空，请检查!"];
                return NO;
            }
            
            if(IsStrEmpty(self.basicInfoView.customerNameView.contentText)){
                [self showAlterWhitErrorStr:@"联系人为空，请检查!"];
                return NO;
            }
            if(IsStrEmpty(self.basicInfoView.customerPhoneNumberView.contentText)){
                [self showAlterWhitErrorStr:@"联系人号码为空，请检查!"];
                return NO;
            }
            
            if([_recordModel.VEHICLE_LIFE_STATUS isEqualToString:@"25271003"]||[_recordModel.VEHICLE_LIFE_STATUS isEqualToString:@"25271004"]){
                
                if(IsStrEmpty(_recordModel.BUSINESS_KIND)||[_recordModel.BUSINESS_KIND isEqualToString:@"0"]){
                    [self showAlterWhitErrorStr:@"车辆性质为空，请检查!"];
                    return NO;
                    
                }
            }
            
        }

    if(!self.selectedRepairTypes || self.selectedRepairTypes.count == 0)
    {
        [self alertMessage:@"维修类型为空，请检查!"
                 withBlock:^{
        }];

        return NO;
    }
   

    return YES;
}





#pragma mark    提交验证数据
- (BOOL)checkFormSubmitData{
    
    if([ICrEAMTool isVaildRealName:self.basicInfoView.customerNameView.contentText] == NO ){
        
        [self.view showString:@"联系人姓名有误，请修改后保存！" forSeconds:1.5];
        return NO;
    }
    if([ICrEAMTool validateMobile:self.basicInfoView.customerPhoneNumberView.contentText] == NO){
        
        [self.view showString:@"联系人手机号有误，请修改后保存！" forSeconds:1.5];
        return NO;
    }

    //上次里程
    NSInteger mileage = [self.basicInfoView.currentMileageView.contentText integerValue];
    
    if([self.carModel.lastMillions integerValue] > mileage || [self.basicInfoView.currentMileageView.contentText integerValue]>mileage) {
        [self alertMessage:@"当前进站里程小于上次进站里程，请检查！"
                 withBlock:^{
                     
                 }];
        
        
        return NO;
        
    }else if ([self.basicInfoView.currentMileageView.contentText integerValue]  == 0 ){
        
        [self alertMessage:@"请检查当前行驶里程！"
                 withBlock:^{
                 }];
        
        return NO;
        
    }else if([self.carModel.lastMillions integerValue] == 0 && mileage == 0){
        
        
        [self alertMessage:@"当前进站里程与上次进站里程相同，请检查！"
                 withBlock:^{
                 }];
        return NO;
        
    }

    if(IsStrEmpty(_recordModel.VEHICLE_LIFE_STATUS)||[_recordModel.VEHICLE_LIFE_STATUS isEqualToString:@"0"]){
        [self showAlterWhitErrorStr:@"车辆生命周期为空，请检查!"];
        
    }else{
        //待上牌
        if(IsStrEmpty(_recordModel.OWNER_NAME)||IsStrEmpty(self.basicInfoView.ownerNameView.contentText)){
            [self showAlterWhitErrorStr:@"车主姓名为空，请检查!"];
            return NO;
        }
        if(IsStrEmpty(_recordModel.VIN)||IsStrEmpty(self.basicInfoView.vinNumberView.contentText)){
            [self showAlterWhitErrorStr:@"VIN为空，请检查!"];
            return NO;
        }
        if(IsStrEmpty(_recordModel.LICENSE)||IsStrEmpty(self.basicInfoModel.LICENSE)){
            [self showAlterWhitErrorStr:@"车牌为空，请检查!"];
            return NO;
        }
        
        if(IsStrEmpty(_recordModel.MODEL_CODE)||IsStrEmpty(self.basicInfoModel.MODEL_CODE)){
            [self showAlterWhitErrorStr:@"车型代码为空，请检查!"];
            return NO;
        }
        if(IsStrEmpty(_recordModel.SALES_DATE)||IsStrEmpty(self.basicInfoView.invoiceDateView.contentText)){
            [self showAlterWhitErrorStr:@"购车日期为空，请检查!"];
            return NO;
        }
        if(IsStrEmpty(self.basicInfoView.customerNameView.contentText)){
            [self showAlterWhitErrorStr:@"联系人为空，请检查!"];
            return NO;
        }
        if(IsStrEmpty(self.basicInfoView.customerPhoneNumberView.contentText)){
            [self showAlterWhitErrorStr:@"联系人号码为空，请检查!"];
            return NO;
        }
        if([_recordModel.VEHICLE_LIFE_STATUS isEqualToString:@"25271003"]||[_recordModel.VEHICLE_LIFE_STATUS isEqualToString:@"25271004"]){
            
            if(IsStrEmpty(_recordModel.OWNER_PROPERTY)){
                [self showAlterWhitErrorStr:@"车主性质为空，请检查!"];
                return NO;
            }
            if(IsStrEmpty(_recordModel.BUSINESS_KIND)||[_recordModel.BUSINESS_KIND isEqualToString:@"0"]){
                [self showAlterWhitErrorStr:@"车辆性质为空，请检查!"];
                return NO;
            }
        }

       

    }
    
    return YES;
}
-(void)showAlterWhitErrorStr:(NSString *)errorStr{
    [self alertMessage:errorStr
             withBlock:^{
//                 _recordModel = nil;
                 [self setupCreateFileView];
                 
             }];
    
}
//选择套餐需要的车型 工时
-(void)getLABOUR_PRICE:(NSString *)carModel{

    ICMRequestManager *manager = [[ICMRequestManager alloc]init];
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    if(IsStrEmpty(carModel)){
        carModel = @"";
    }
    [parameters setObject:carModel forKey:@"MODEL_CODE"];
    [manager startGetRequestWithURL:queryLabourPrice parameters:parameters inHudView:self.view andResultBlock:^(id data, NSString *failText) {
        if ([data[@"CODE"] integerValue] == 200) {
            
            LABOUR_PRICE = data[@"LABOUR_PRICE"];
            self.partsView.SERIES_LABOUR_PRICE = LABOUR_PRICE;
            self.partsView.repairTypes = self.selectedRepairTypes;
            self.partsView.delegate = self;
            self.partsView.modelCode = carModel;
            self.partsTopModel = [[ICMPartsTopModel alloc]init];
            self.partsTopModel.LABOUR_PRICE = LABOUR_PRICE;
            [self.partsView setupPartsViewWithPartsTopModel:self.partsTopModel];
        }
        
        }];

}

-(void)addPlantAlter:(NSString *)textFieldAreaAndPlateStr{
    _plantAlterCtr = [[PlateNumberChangeAlterViewController alloc]init];
    _plantAlterCtr.vinStr = self.basicInfoView.vinNumberView.contentText;
    _plantAlterCtr.oldCarNumberStr = self.carModel.carNum;
    _plantAlterCtr.neoCarNumberStr = textFieldAreaAndPlateStr;
    changeCarNumber = textFieldAreaAndPlateStr;
    _plantAlterCtr.view.centerX = self.blankView.frame.size.width/2;
    _plantAlterCtr.view.centerY = Window.frame.size.height/2;
    
    [_plantAlterCtr.yesButton addTarget:self action:@selector(yesAction) forControlEvents:UIControlEventTouchUpInside];
    [_plantAlterCtr.noButton addTarget:self action:@selector(noAction) forControlEvents:UIControlEventTouchUpInside];
    
    [self addChildViewController:_plantAlterCtr];
    [self.view addSubview:_plantAlterCtr.blankView];


}




//车牌变更提示事件
-(void)yesAction{
    switch (changeCarNumberType) {
        case 1:
            self.carModel.carNum = changeCarNumber;
            if(_isEditType == YES){
                self.recordModel.LICENSE = changeCarNumber;
            }
            break;
        case 2:
            self.carModel.carNum = changeCarNumber;
            break;
        case 3:
            self.carModel.carNum = changeCarNumber;
            [self resetViewAfterSelectLicense];

            break;
            
        default:
            break;
    }
    [_plantAlterCtr hideAllView];
}
-(void)noAction{
    
    switch (changeCarNumberType) {
        case 1:
            if(IsStrEmpty(self.carModel.carNum)){
                //快速建档中没有车牌时 输入车牌的回调取值
                NSString *createSubAreaStr = [self getModelAreaStr:self.recordModel.LICENSE];
                NSString *createPlateStr = [self getModelPlateStr:self.recordModel.LICENSE];
                self.basicInfoView.selectAreaView.contentText = createSubAreaStr;
                self.basicInfoView.plateNumberView.contentText = createPlateStr;
                
                }else{
                    NSString *modelAreaStr = [self getModelAreaStr:self.carModel.carNum];
                    NSString *modelPlateStr = [self getModelPlateStr:self.carModel.carNum];
                    self.basicInfoView.selectAreaView.contentText = modelAreaStr;
                    self.basicInfoView.plateNumberView.contentText = modelPlateStr;
                                        
                };

            break;
        case 2:
            if(IsStrEmpty(self.carModel.carNum)){
                //快速建档中没有车牌时 输入车牌的回调取值
                NSString *createSubAreaStr = [self.recordModel.LICENSE substringToIndex:1];
                NSString *createPlateStr = [self.recordModel.LICENSE substringFromIndex:1];
                self.basicInfoView.selectAreaView.contentText = createSubAreaStr;
                self.basicInfoView.plateNumberView.contentText = createPlateStr;
                }
            else{
                NSString *modelAreaStr = [self getModelAreaStr:self.carModel.carNum];
                NSString *modelPlateStr = [self getModelPlateStr:self.carModel.carNum];
                self.basicInfoView.selectAreaView.contentText = modelAreaStr;
                self.basicInfoView.plateNumberView.contentText = modelPlateStr;
            
            }

            break;
        case 3:
            [self resetViewAfterSelectLicense];
            break;
               default:
            break;
    }
    [_plantAlterCtr hideAllView];
}

@end
